none
The parameter of method Process.Start can not accept relative path starting with slash ? RRS feed

  • Question

  • Hi

    I have tried to Process.Start exe file by using relative path like this "./notepad.exe" (starting with slash)

    But, the FileNotFound exception has occurred, in the fact it exists indeed.

    Instead of "./notepad.exe" ,  when calls the Process.Start with  ".\notepad.exe"(starting with back slash), it starts successfully.

    The question is that Process.Start can not accept relative path starting with slash ?

    Env: Windows 7, VS 2010

    Thank you very much.

    Thursday, October 23, 2014 9:30 AM

Answers

  • If you start with relative path, neither slash and back slash are successful. But Process.Start("notepad.exe") can be successful.

    For full path, both slash and back slash can be successful:

    Process.Start(@"C:\Program Files\Notepad\notepad.exe"); // successfull

    or

    Process.Start(@"C:/Program Files/Notepad/notepad.exe"); // successful

    Hope above help.

    Monday, October 27, 2014 7:12 AM
  • Even though it works most of the time, slash is actually not a path delimiter on Windows. Backslash is.

    Also it is a bad idea to use relative paths when starting an executable, because current directory is not guaranteed to be the same as application startup directory. This also might be insecure, because someone may compromise your app by making it run the wrong executable, which might cause unpredicted (and possibly dangerous/fraudulent) results.

    The best solution is to combine (Path.Combine) application base directory with your relative path, and then start executable using absolute path.

    Tuesday, October 28, 2014 12:46 AM

All replies

  • Hello Typing,

    >>The question is that Process.Start can not accept relative path starting with slash ?

    It seems to be that since even with windows 8.1 operation system. My opinion is that inside this class, the slash should be an invalid character.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 24, 2014 3:19 AM
    Moderator
  • If you start with relative path, neither slash and back slash are successful. But Process.Start("notepad.exe") can be successful.

    For full path, both slash and back slash can be successful:

    Process.Start(@"C:\Program Files\Notepad\notepad.exe"); // successfull

    or

    Process.Start(@"C:/Program Files/Notepad/notepad.exe"); // successful

    Hope above help.

    Monday, October 27, 2014 7:12 AM
  • Even though it works most of the time, slash is actually not a path delimiter on Windows. Backslash is.

    Also it is a bad idea to use relative paths when starting an executable, because current directory is not guaranteed to be the same as application startup directory. This also might be insecure, because someone may compromise your app by making it run the wrong executable, which might cause unpredicted (and possibly dangerous/fraudulent) results.

    The best solution is to combine (Path.Combine) application base directory with your relative path, and then start executable using absolute path.

    Tuesday, October 28, 2014 12:46 AM