如何用命令运行程序?
问题描述:
我需要使用命令在Windows-CE或Windows-Mobile中运行程序如何用命令运行程序?
例如:RunMe.exe true
或RunMe.exe false
如果程序返回true,程序会做一些事情,如果程序返回false
该计划将做其他事情。
我该如何做到这一点?
答
你的问题还不清楚。
如果您想要请写这样的程序,请使用string[] args
参数至Main()
。
(或叫Environment.GetCommandLineArguments()
)
如果你想运行这样的程序,调用Process.Start
。
答
从this question(其中有从msdn):
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
答
如果你想这样做,而无需编写另一个程序,你可以创建一个快捷方式文件,使用所需的命令行选项启动应用程序。
的快捷方式文件的格式如下:
[number of ASCII characters after pound sign allocated to command-line arguments]#[command line] [optional parameters]
例如:
40#\Windows\MyApp.exe parameter1 parameter2