【发布时间】:2014-05-26 14:10:20
【问题描述】:
我正在尝试使用此代码创建一个目录,以查看代码是否正在执行,但由于某种原因,它执行时没有错误,但该目录从未创建。我的代码中是否存在错误?
var startInfo = new
var startinfo = new ProcessStartInfo();
startinfo.WorkingDirectory = "/home";
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c cd Desktop && mkdir hey";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start ();
Console.WriteLine ("Shell has been executed!");
Console.ReadLine();
【问题讨论】:
-
工作目录是什么?
-
-
我假设您最终确实在尝试做其他事情(而不是创建目录)。否则,Directory.CreateDirectory(string) 似乎是比通过 shell 更好的选择。
-
/home 目录下是否存在桌面?如果是这样,您为什么不将 WorkingDirectory 设置为“/home/Desktop”并只执行 mkdir 命令?我觉得这是XY问题:meta.stackexchange.com/questions/66377/what-is-the-xy-problem
-
我想执行一个保存在我桌面上的 shell 脚本。