ProcessStartInfo参数 [英] ProcessStartInfo arguments

查看:197
本文介绍了ProcessStartInfo参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个过程,需要一些参数.我希望它从C#开始.我已经在快捷方式中尝试过相同的参数,并且可以正常工作.另一方面,在c#中没有,因此这里是参数.参数格式正确,但在-k

I have a process, which takes some arguments. I want it to start from C#. I have tried the same arguments in shortcut and it works. On the other hand, in c# it doesnt, so here are the arguments. The argument format is correct, but i get a wrong argument error at -k

ProcessStartInfo prf = new ProcessStartInfo("C:\\" + "argstest.exe");       
prf.UseShellExecute =true;
prf.Arguments = "-l http://test.tes1:testa@testb.testing.com:3333/ -k testing TYPE=0 USER=1 COUNT=10";
Process.Start(prf);

进程启动,但是立即关闭,因为应该测试的-k参数没有发送到程序. 我曾尝试在-l之前添加一个"空格,但同样,也尝试过@"-l ..."

Process starts, but closes instantly, because the -k argument which should be testing doesnt get sent to program. I have tried adding a " " space before -l but same, also tried @" -l ..."

推荐答案

我测试了您的代码,但未发现任何问题.也许您觉得这对跟踪问题很有用,我做到了,您也可以这样做:

I tested your code and did not find any issues. Perhaps you find this useful in tracking down your problem, I did this and you can do the same:

您要运行的控制台应用程序,我这样做:

The Console App that you are trying to run, I did this:

static void Main(string[] args)
{
    foreach (var arg in args)
    {
        Console.WriteLine(arg);
    }
    Console.ReadLine();
}

在另一个控制台应用程序中,就这样:

From another console app, just this:

static void Main(string[] args)
        {
            ProcessStartInfo prf = new ProcessStartInfo("ConsoleApplication1.exe");
            prf.UseShellExecute = true;
            prf.Arguments = "-l http://test.tes1:testa@testb.testing.com:3333/ -k testing TYPE=0 USER=1 COUNT=10";
            Process.Start(prf);
        }

输出:

-1
http://test.tes1:testa@testb.testing.com:3333/
-k
testing
TYPE=0
USER=1
COUNT=10

这就是让我相信问题不在于Process.Start()方面的原因,而在于您的其他应用程序正在解析参数的方式.至于为什么快捷方式起作用而不能起作用的原因,也许您应该复制/粘贴您正在使用的快捷方式,而不是真正确定该快捷方式.

This is what leads me to believe the problem isn't on the Process.Start() side, but in the way that your other app is parsing the arguments. As for why the shortcut works and this doesn't, maybe you should copy/paste the shortcut that you are using, not really sure on that one.

这篇关于ProcessStartInfo参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆