如果我使用ShellExecute(或在.net中System.Diagnostics.Process.Start())运行进程,则启动文件名进程不需要是完整路径.
如果我想开始记事本,我可以使用
Process.Start("notepad.exe");
Run Code Online (Sandbox Code Playgroud)
代替
Process.Start(@"c:\windows\system32\notepad.exe");
Run Code Online (Sandbox Code Playgroud)
因为direcotry c:\windows\system32是PATH环境变量的一部分.
如何在不执行进程且不解析PATH变量的情况下检查PATH上是否存在文件?
System.IO.File.Exists("notepad.exe"); // returns false
(new System.IO.FileInfo("notepad.exe")).Exists; // returns false
Run Code Online (Sandbox Code Playgroud)
但我需要这样的东西:
System.IO.File.ExistsOnPath("notepad.exe"); // should return true
Run Code Online (Sandbox Code Playgroud)
和
System.IO.File.GetFullPath("notepad.exe"); // (like unix which cmd) should return
// c:\windows\system32\notepad.exe
Run Code Online (Sandbox Code Playgroud)
是否有预定义的类可以在BCL中执行此任务?
在我的脚本中,我即将运行一个命令
pandoc -Ss readme.txt -o readme.html
Run Code Online (Sandbox Code Playgroud)
但我不确定是否pandoc已安装.所以我想做(伪代码)
if (pandoc in the path)
{
pandoc -Ss readme.txt -o readme.html
}
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做呢?