如何在c#中执行终端命令
how to execute a terminal command in c#
看了很多post,其中有这一篇
c# - 打开终端进程并传递命令?
我在我的代码中做了完全相同的事情
Process proc = new System.Diagnostics.Process ();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c \" " + command + " \"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start ();
where command = export DISPLAY=:0.0
它进入我的陷阱,"pplicationName='/bin/bash', CommandLine='-c " cd .. "', CurrentDirectory='', Native error= 系统找不到指定的文件。"
我有什么不同之处?即使我尝试调整 set command = "cd .." 它也不起作用
您或许应该尝试设置可执行文件的完整路径。
proc.StartInfo.FileName = "C:/SOMEPATH/Bash.exe";
我假设您在指定相对路径时并未解析它。可能是因为您没有为进程设置工作目录,所以它的当前目录和您认为的当前目录不同。
看了很多post,其中有这一篇
c# - 打开终端进程并传递命令?
我在我的代码中做了完全相同的事情
Process proc = new System.Diagnostics.Process ();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c \" " + command + " \"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start ();
where command = export DISPLAY=:0.0
它进入我的陷阱,"pplicationName='/bin/bash', CommandLine='-c " cd .. "', CurrentDirectory='', Native error= 系统找不到指定的文件。"
我有什么不同之处?即使我尝试调整 set command = "cd .." 它也不起作用
您或许应该尝试设置可执行文件的完整路径。
proc.StartInfo.FileName = "C:/SOMEPATH/Bash.exe";
我假设您在指定相对路径时并未解析它。可能是因为您没有为进程设置工作目录,所以它的当前目录和您认为的当前目录不同。