mono Process.Start how to find bash?

霸气de小男生 提交于 2019-12-08 02:21:10

问题


In my webapp i do the below. I know its correct because i tried 1) dumping start_sz to a text file 2) su www-data 3) copy/paste the extract string and it worked.

var start_sz = string.Format(@"bash -c 'ln ""{2}/{0}"" ""{2}/{1}""'", fn, newfn, System.IO.Directory.GetCurrentDirectory());
Process.Start(start_sz);

I get the exception below so with reasoning above i believe its saying bash cannot be found.

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

So, how do i fix this? basically i need to create a hardlink (soft is ok too) at run time in my asp.net app.

I thought maybe i need the full bash path so i tried /bin/bash -c however that didn't work either.


回答1:


Why not call ln directly? Without bash?

Process.Start("ln", params);

Also you may need to specify the full path:

Process.Start("/bin/ln", params);

In fact, Process.Start("bash") works for me, thus check $PATH environment variable, etc.




回答2:


No, you know it's correct when used from a shell. That shell will take the path into account, unlike Process.Start.

Just specify the full path to bash, which is almost certainly /bin/bash.



来源:https://stackoverflow.com/questions/4699109/mono-process-start-how-to-find-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!