Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start("echo", "%cd%") throws W32Exception File Not Found

When I try to do Process.Start("echo", "%cd%") it raises a System.ComponentModel.Win32Exception: The system cannot find the file specified. When I do this manually in cmd it just works like it should. I never knew that there's a difference...

Also, when I do File.Exists(logfile.txt) (w/o path) of a file that should definitely be there, it returns false. This is btw the reason for the echo above: debugging...

This error doesn't occur on my developement machine, only on another one where I am testing on.

The Path variable looks normal. Both are WinXP. Both are running .NET 3.5

like image 355
ihavenoaccount Avatar asked Aug 22 '11 09:08

ihavenoaccount


2 Answers

Try Process.Start("cmd.exe", "/c echo %CD%")

as far as echo is not an executable but a command inside.

like image 146
abatishchev Avatar answered Sep 28 '22 15:09

abatishchev


You can use System.Environment.CurrentDirectory if you want to pass the working directory of your application to cmd. AFAIK %CD% is internal to cmd, that's why Process.Start won't expand it. For ordinary environment variables you can use Environment.ExpandEnvironmentVariables.

like image 35
JayK Avatar answered Sep 28 '22 14:09

JayK