Process.Start cmd导致“无法识别”

时间:2021-12-01 22:51:48

When launching an application directly, the application is launched, but when launched through cmd - it's not.

直接启动应用程序时,应用程序会启动,但是当通过cmd启动时 - 它不是。

For example:

例如:

Works:

作品:

Process.Start("firefox");

Doesn't work:

不起作用:

Process.Start(
    new ProcessStartInfo
    {
        FileName = "cmd",
        Arguments = "/k firefox"
    });

I've tried setting UseShellExecute to true, but to no avail. I still get:

我已经尝试将UseShellExecute设置为true,但无济于事。我还是得到:

'firefox' is not recognized as an internal or external command, operable program or batch file.

'firefox'不被识别为内部或外部命令,可操作程序或批处理文件。

So, yes, I can specify the complete path. But is there a way to avoid that? Or in other words - what's the difference between the two that makes the second fail?

所以,是的,我可以指定完整的路径。但有没有办法避免这种情况?换句话说 - 两者之间的区别是什么让第二次失败?

1 个解决方案

#1


3  

Haven't tested it but I guess you are probably looking for the start command:

没有测试过,但我想你可能正在寻找启动命令:

Process.Start(
    new ProcessStartInfo
    {
        FileName = "cmd",
        Arguments = "/k start firefox"
    });

As a tip, simply run "firefox" in a command prompt -> you'd get the same error message.

作为提示,只需在命令提示符下运行“firefox” - >您将收到相同的错误消息。

#1


3  

Haven't tested it but I guess you are probably looking for the start command:

没有测试过,但我想你可能正在寻找启动命令:

Process.Start(
    new ProcessStartInfo
    {
        FileName = "cmd",
        Arguments = "/k start firefox"
    });

As a tip, simply run "firefox" in a command prompt -> you'd get the same error message.

作为提示,只需在命令提示符下运行“firefox” - >您将收到相同的错误消息。