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

╄→гoц情女王★ 提交于 2019-12-01 19:19:39

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

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

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.

This is because echo is a console command, not an application - it isn't housed in an executable file of its own.

As for your file existence issue, if you just use the file name without the path then it will look in the working directory, this could be different to the directory containing the executing application, and completely different to where you think the files ought to be - you should fully qualify your paths after making yourself aware of the applications configuration.

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