Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从C#应用程序执行linux shell脚本?_C#_Linux_Bash_Shell_Cygwin - Fatal编程技术网

如何从C#应用程序执行linux shell脚本?

如何从C#应用程序执行linux shell脚本?,c#,linux,bash,shell,cygwin,C#,Linux,Bash,Shell,Cygwin,我有一个linux shell脚本,可以在windows中使用CygWin终端手动执行 sh E://Work/sync.sh E://Work/Voice/Temp 但是,当我试图用相同的参数在我的C#应用程序中运行shell脚本时,我遇到了一些困难 string command = "E://Work/sync.sh E://Work/Voice/Temp"; ProcessStartInfo psi = new ProcessStartInfo(@"C:\cygwin64\bin\bas

我有一个linux shell脚本,可以在windows中使用CygWin终端手动执行

sh E://Work/sync.sh E://Work/Voice/Temp
但是,当我试图用相同的参数在我的C#应用程序中运行shell脚本时,我遇到了一些困难

string command = "E://Work/sync.sh E://Work/Voice/Temp";
ProcessStartInfo psi = new ProcessStartInfo(@"C:\cygwin64\bin\bash.exe", command);
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);
Console.WriteLine(p.StandardError.ReadToEnd());
Console.WriteLine(p.StandardOutput.ReadToEnd());
这给了我一个错误:

E://Work/sync.sh: line 47: rm: command not found
E://Work/sync.sh: line 48: mkdir: command not found
E://Work/sync.sh: line 50: ls: command not found
E://Work/sync.sh: line 59: ls: command not found
E://Work/sync.sh: line 60: rmdir: command not found
然后我尝试了另一种方法

ProcessStartInfo psi = new ProcessStartInfo(@"C:\cygwin64\bin\bash.exe");
psi.Arguments = "--login -c sh E://Work/sync.sh  E://Work/Voice/Temp";
Process p = Process.Start(psi);
这将启动CygWin命令提示符,如下所示:

然后,如果我手动输入命令,它就会工作。
E://Work/sync.sh E://Work/Voice/Temp


我如何在没有任何手动输入的情况下从应用程序自动执行脚本?

在谷歌搜索之后,我找到了一种方法。我所要做的就是将--login-c改为--login-I


试试psi.Arguments=“--login-c/cygdrive/e/Work/sync.sh/cydrive/e/Work/Voice/Temp”;不起作用。显示错误-“没有这样的文件或目录”
ProcessStartInfo psi = new ProcessStartInfo(@"C:\cygwin64\bin\bash.exe");
psi.Arguments = "--login -i E://Work/sync.sh  E://Work/Voice/Temp";
Process p = Process.Start(psi);