如何用参数执行shell命令?

And*_*nca 0 .net c# shell command arguments

我试图用C#中的参数执行shell命令,并抛出" 系统找不到指定的文件 ".

我试过了:

p.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\timesync\\NistClock.exe sync";
Run Code Online (Sandbox Code Playgroud)

路径是正确的100%NistClock.exe在没有参数"sync"的情况下运行时执行

Adr*_*tti 6

你应该改变你的代码:

p.StartupInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "timesync\\NistClock.exe");
p.StartupInfo.Arguments = "sync";
Run Code Online (Sandbox Code Playgroud)


jue*_*n d 5

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