2

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.

Community
  • 1
  • 1

2 Answers2

2

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • ah #$%^&*(! i needed to call Process.Start with (string, string). It thought the args were part of the filename thus file not found. Why doesnt process.start force you to use (name,""), its much less error prone. –  Jan 15 '11 at 11:05
  • @acidzombie24: `Process.Start(string)` creates `new ProcessStartInfo(string)` and `Process.Start(string,string)` - `new ProcessStartInfo(string,string)`. Look at `ProcessStartInfo` constructors: one sets `arguments`, another - not. So that's just syntax-sugar overload – abatishchev Jan 15 '11 at 11:17
  • 1
    Its bad tasting sugar, i dont want it. –  Jan 15 '11 at 11:31
1

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • A longshot but do you know why Process.Start has a single param overload instead of forcing 2 params (bin, args). I could swear, i had the exact same error a year ago when i last used Process.Start (way to farback and infrequent to remember. It bit me twice so many i'll remember it from now on) –  Jan 15 '11 at 11:08
  • @acidzombie24: Not JonSkeet, but there are actually a ton of cases where you want to execute an executable and don't need to pass any params. – Guvante Feb 04 '16 at 00:52