c# - mono Process.Start 如何找到 bash?

标签 c# linux mono process.start

在我的网络应用程序中,我执行以下操作。我知道它是正确的,因为我尝试了 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/

相关文章:

c# - 使用字符串中存在的分隔符拆分字符串

C# WebAPI 2反序列化产生空值但没有异常

c# - 编译错误

linux - 如何在 Unix/Linux 操作系统上移动给定数量的随机文件

linux - Mono/Ubuntu 中的 ReadProcessMemory Win32API?

c# - 在 Ubuntu/Mono 上运行的 HttpListener 返回 400 错误请求

mysql - 什么版本的 MySQL Connector 可以与 Mono 2.10.1 一起使用

c# - 如何在 WPF 窗口中显示屏幕保护程序的预览

linux - Linux启动应用程序的途径和方法有哪些

c - 在以下 NASM 任务中需要帮助