Eric
Eric

Reputation: 1472

How to view Process.Start() Arguments as they are passed to executable

I'm trying to run a fortran executable with Process.Start and it is not working.

Process proc = new Process();
string args = "<C:\\file.in> C:\\file.out";
proc.StartInfo = new ProcessStartInfo(AppName, args);
proc.Start();

if I paste those arguments into a command window the application runs as expected. proc.Start() does not run as expected.

Any ideas how I can view what Start is actually passing as arguments? My gut feeling is that this is a quotes issue.

The executable launches and hangs, so I'm confident the AppName is getting passed in correctly, it looks like an argument problem.

I tried setting the WorkingDirectory to that of the input and output files as suggested in this question: process.start() arguments but that did not work.

Upvotes: 1

Views: 1029

Answers (2)

Thomas C. G. de Vilhena
Thomas C. G. de Vilhena

Reputation: 14565

Your args string is exactly what is being passed as arguments to the executable. You can double check it reading your Process ProcessStartInfo.Arguments Property.

Something similar happened to me once, i.e., calling the executable from the command line worked and from code didn't, and it turned out that when called from the command line the executable was running on my PC's [C:] drive, and when called from code it was running on my PC's [E:] drive, which was full!

To check which directory your application is using to run the executable use the Directory.GetCurrentDirectory Method.

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941495

Redirection with the < and > command line operators is a feature that's implemented by the command line processor. Which is cmd.exe. Use its /c argument to execute just a single command:

string args = "/c " + AppName + " < C:\\file.in > C:\\file.out";
proc.StartInfo = new ProcessStartInfo("cmd.exe", args);
proc.Start();

Upvotes: 1

Related Questions