C#使用多个参数启动应用程序
我一直在尝试从C#应用程序启动应用程序,但无法正常启动。从cmd中,应用程序加上参数启动一个小窗口,显示输出,然后将应用程序最小化到系统托盘 使用下面的代码从C#应用程序启动应用程序会导致进程出现在任务管理器中,但除此之外,没有输出窗口,没有系统托盘图标。可能是什么问题C#使用多个参数启动应用程序,c#,process,C#,Process,我一直在尝试从C#应用程序启动应用程序,但无法正常启动。从cmd中,应用程序加上参数启动一个小窗口,显示输出,然后将应用程序最小化到系统托盘 使用下面的代码从C#应用程序启动应用程序会导致进程出现在任务管理器中,但除此之外,没有输出窗口,没有系统托盘图标。可能是什么问题 myProcess.StartInfo.FileName = ...; myProcess.StartInfo.Arguments = ...; myProcess.Start(); 还试着通过了下面的
myProcess.StartInfo.FileName = ...;
myProcess.StartInfo.Arguments = ...;
myProcess.Start();
还试着通过了下面的测试
myProcess.StartInfo.RedirectStandardOutput = true; //tried both
myProcess.StartInfo.UseShellExecute = false; //tried both
myProcess.StartInfo.CreateNoWindow = false;
使用
Process.Start(Filename, args)
也不管用。如果您能帮助我解决这个问题,我将不胜感激
更新:
我认为问题可能是要传递给流程的多个参数
RunMode=Server;CompanyDataBase=dbname;UserName=user;PassWord=passwd;DbUserName=dbu;Server=localhost;LanguageCode=9
问候
System.Diagnostics.Process.Start(FileName,args);
乙二醇
我看不出你的密码有任何错误。我已经编写了一个小程序,将其参数打印到控制台
static void Main (string[] args)
{
foreach (string s in args)
Console.WriteLine(s);
Console.Read(); // Just to see the output
}
然后我把它放在C:,作为应用程序“PrintingArgs.exe”的名称,所以我写了另一个,执行第一个:
Process p = new Process();
p.StartInfo.FileName = "C:\\PrintingArgs.exe";
p.StartInfo.Arguments = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18";
p.Start();
这将为我提供所需的数字列表输出。调用PrintingArgs的应用程序在到达p.Start()时退出,这可以通过使用p.WaitForExit()避免代码>或只是Console.Read()代码>。
我还使用了p.UseShellExecute
和p.CreateNoWindow
。只有在这种情况下
p.UseShellExecute = false;
p.CreateNoWindow = true;
使PrintingArgs应用程序不显示窗口(即使我仅放置p.CreateNoWindow=true
它显示窗口)
现在我想到的是,可能您以错误的方式传递args,导致另一个程序失败并立即关闭,或者您没有指向正确的文件。检查路径和名称,以便发现任何可能忽略的错误。
此外,使用
Process.Start(fileName, args);
不会在流程实例中使用您使用StartInfo设置的信息
希望这会有所帮助,
您是否已将ProcessWindowsStyle设置为隐藏?
这是我的代码,工作正常:
Process p=new Process();
p.StartInfo.FileName = filePath;//filePath of the application
p.StartInfo.Arguments = launchArguments;
p.StartInfo.WindowStyle = (ProcessWindowStyle)ProcessStyle;//Set it to **Normal**
p.Start();
不确定是否有人还在关注这一点,但以下是我的想法
string genArgs = arg1 + " " + arg2;
string pathToFile = "Your\Path";
Process runProg = new Process();
try
{
runProg.StartInfo.FileName = pathToFile;
runProg.StartInfo.Arguments = genArgs;
runProg.StartInfo.CreateNoWindow = true;
runProg.Start();
}
catch (Exception ex)
{
MessageBox.Show("Could not start program " + ex);
}
在字符串中添加空格可以将两个参数传递到我想要运行的程序中。执行代码后,程序运行正常。尝试将参数括在单引号中。
string genArgs = arg1 + " " + arg2;
string pathToFile = "Your\Path";
Process runProg = new Process();
try
{
runProg.StartInfo.FileName = pathToFile;
runProg.StartInfo.Arguments = genArgs;
runProg.StartInfo.CreateNoWindow = true;
runProg.Start();
}
catch (Exception ex)
{
MessageBox.Show("Could not start program " + ex);
}