Failed to execute Shell C #

1

Friends, I ask for help to solve a small problem.

I'm running SQL command through sqlCmd and Shell in C #, but the file is in a folder that contains "space" as follows.

Path: D: \ Sandboxes \ CIA Project \ 3-Development \ Scripts \ DDL \ DDL_T_DDW_CIA_PRODUTO_INDEXADOR.sql

When I run the Shell, the error is displayed: Win32Exception: The system can not find the file specified

Is there any way to make Shell understand the "space" in Path?

Following command is being executed.

System.Diagnostics.Process.Start (strScript)

Thank you

Update

Include the double quotes, but the error remains.

sqlcmd -S servidor -U sa -P senha -i "D:\Pessoal\luiz.junior\Documents\Visual Studio 2012\Projects\AppNolock\AppNolock\bin\x86\Debug\Temp\Script.sql"

Error : The system can not find the file specified

    
asked by anonymous 15.07.2015 / 17:45

2 answers

2

Add quotes and escape them as follows:

strScript = "sqlcmd -S server -i \"D:\Sandboxes\Projeto CIA\3-Desenvolvimento\Scripts\DDL\DDL_T_DDW_CIA_PRODUTO_INDEXADOR.sql\""

Note that you have to escape the backslashes .

See the result here .

    
15.07.2015 / 18:06
0

I solved the problem.

Instead of simply running the command line through Process.Start, I created a .bat file with the command line and it was executed by Process.Start.

            StringBuilder strScript = new StringBuilder();                
            var process = new System.Diagnostics.ProcessStartInfo();

            strScript.Append(String.Format("sqlcmd -S {0} -U sa -P mudar.123 -i \"{1}\"", cbServidor.Text, pathFile));
            Dados.GravarArquivo(PathTemp + @"\cmd.bat",strScript);
            FileInfo file = new FileInfo(PathTemp + @"\cmd.bat");

            process.WorkingDirectory = file.Directory.FullName;
            process.FileName = file.Name;
            process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            System.Diagnostics.Process.Start(process).WaitForExit();
            System.Threading.Thread.Sleep(100);
    
14.08.2015 / 15:29
How to calculate the time difference between certain hours? [duplicate] PHP - How to insert a variable link inside a href variable?