【发布时间】:2019-12-02 05:25:03
【问题描述】:
我正在尝试使用 C# 运行批处理文件
用于测试的批处理文件包含
msg * Test
如果我手动运行它就可以了。
然后我用下面的代码来运行这个.bat文件
filePath = full path to batch file
var startInfo = new ProcessStartInfo
{
Arguments = "/C \"" + filePath + "\"",
FileName = "cmd.exe",
UseShellExecute = true
};
Process p = Process.Start(startInfo);
它不起作用 ->
cannot find msg
我做错了什么?
附:不应更改批处理文件。
【问题讨论】:
-
从 C# 运行时,
msg在上下文中是否可用?是在同一个目录下还是在你的PATH环境变量中? -
@Neijwiert 如何检查?即使我将完整的文件路径放到 msg.exe 中,它也不起作用
-
检查您的 Windows PATH 环境变量并检查
Environment.CurrentDirectory
标签: c# batch-file process environment-variables processstartinfo