1

I need to run a bunch of commands in C# in order for my program to run correctly. Previously, this script ran flawlessly and I used to get the desired output my program needs in order to compile and run correctly.

This is the script I have currently

Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = @"/C mkdir C:\IL & del Output.il & cd C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools & ildasm /out=C:\IL\Output.il " + filePath;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();

Filepath is a parameter I pass back to this method. This parameter contains the file's URL.

When the filepath is loaded into the application now, this set of commands does not run whatsoever. There is no output file or anything. However, these commands run when I enter them manually into Command Prompt.

I've tried this process from this answer, and implemented the following code to try and get this batch file to work.

ProcessStartInfo cmd = new ProcessStartInfo( "cmd",  @"/C mkdir C:\IL & del Output.il & cd C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools & ildasm /out=C:\IL\Output.il" + filePath );
cmd.CreateNoWindow = true;
cmd.UseShellExecute = false;
Process.Start( cmd );

The above method hasn't worked out, and the other posts on here have the same code as my own script, which doesn't help at all.

Is there anything wrong with my script? Or is there a setting that I can enable in Visual Studio?

Thanks for viewing

GipsyD
  • 206
  • 1
  • 3
  • 16
  • 2
    Try to put your file path `C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools` into quotes – Pavel Anikhouski Oct 28 '19 at 09:03
  • 3
    @PavelAnikhouski you don't need to quote the path after `cd`. Run `cd /?` and you'll see *CHDIR command does not treat spaces as delimiters, so it is possible to CD into a subdirectory name that contains a space without surrounding the name with quotes.* but `filePath` needs to be quoted if it contains spaces – phuclv Oct 28 '19 at 09:06
  • @phuclv I cannot thank you enough. Putting filePath in quotes solved the issue. The program runs just fine now. – GipsyD Oct 28 '19 at 09:12
  • Unrelated to your problem, just out of curiosity: why don’t you do the file system stuff directly in your C# code and then use `Process.Start` only to call `ildasm` without the redirection through `cmd`? – Bill Tür stands with Ukraine Oct 28 '19 at 10:02
  • I would have loved to just call ildasm through Process.Start, but my lead developer on this project insists on breaking down the command process into step by step lines to "help speed up and optimize debugging". If I had my way, I would have done just that. – GipsyD Oct 28 '19 at 18:33

0 Answers0