在我的网络应用程序中,我执行以下操作。我知道它是正确的,因为我尝试了 1) 将 start_sz 转储到文本文件 2) su www-data 3) 复制/粘贴提取字符串并且它起作用了。
var start_sz = string.Format(@"bash -c 'ln ""{2}/{0}"" ""{2}/{1}""'", fn, newfn, System.IO.Directory.GetCurrentDirectory());
Process.Start(start_sz);
我得到了下面的异常,所以根据上面的推理,我相信它说 bash 找不到。
Cannot find the specified file
at System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in :0
at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in :0
at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in :0
at System.Diagnostics.Process.Start (System.String fileName) [0x00000] in :0
at MySite.QueueManager.MakeLink (System.String fn) [0x00000] in :0
at MySite.QueueManager.ImageQueue2 () [0x00000] in :0
at MySite.QueueManager.ImageQueue () [0x00000] in :0
那么,我该如何解决这个问题呢?基本上我需要在运行时在我的 ASP.NET 应用程序中创建一个硬链接(hard link)(软链接(soft link)也可以)。
我想也许我需要完整的 bash 路径,所以我尝试了 /bin/bash -c
但这也不起作用。
最佳答案
为什么不直接调用ln
?没有 bash
?
Process.Start("ln", params);
您还可能需要指定完整路径:
Process.Start("/bin/ln", params);
事实上,Process.Start("bash")
对我有用,因此检查$PATH
环境变量等。
关于c# - mono Process.Start 如何找到 bash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4699109/