0

I`m trying to execute a shell command with arguments in C# , and "The system cannot find the file specified" is thrown.

I`ve tried:

p.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\timesync\\NistClock.exe sync";

the path is correct 100% NistClock.exe gets executed when is run without the parameter "sync"

1
  • 1
    Please don't prefix your titles with "c#". That's what the tags are for. Commented Mar 15, 2012 at 13:37

3 Answers 3

6

You should change a little bit your code:

p.StartupInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "timesync\\NistClock.exe");
p.StartupInfo.Arguments = "sync";
Sign up to request clarification or add additional context in comments.

Comments

5
string path = Directory.GetCurrentDirectory() + "\\timesync\\NistClock.exe";                
string args = "sync";
ProcessStartInfo p = new ProcessStartInfo(path, args);
Process process = Process.Start(p);

Comments

3

Use the Arguments property.

p.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\timesync\\NistClock.exe";
p.StartInfo.Arguments = "sync";

By the way, be careful about using Directory.GetCurrentDirectory(). Note that this method can return something different if you're using any file dialogs throughout your application. It might be a better option to use something like Assembly.GetExecutingAssembly().Location instead, and parse the directory from there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.