Process.Start(“echo”, “

后端 未结 3 1402
误落风尘
误落风尘 2021-01-19 00:41

When I try to do Process.Start(\"echo\", \"%cd%\") it raises a System.ComponentModel.Win32Exception: The system cannot find the file specified. Whe

相关标签:
3条回答
  • 2021-01-19 01:21

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

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

    0 讨论(0)
  • 2021-01-19 01:28

    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.

    0 讨论(0)
  • 2021-01-19 01:35

    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.

    0 讨论(0)
提交回复
热议问题