2011-03-01 115 views
0

我需要使用命令在Windows-CE或Windows-Mobile中運行程序如何用命令運行程序?

例如:RunMe.exe trueRunMe.exe false

如果程序返回true,程序會做一些事情,如果程序返回false

該計劃將做其他事情。

我該如何做到這一點?

回答

1

你的問題還不清楚。

如果您想要請寫這樣的程序,請使用string[] args參數至Main()
(或叫Environment.GetCommandLineArguments()

如果你想運行這樣的程序,調用Process.Start

0

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(); 
0

如果你想這樣做,而無需編寫另一個程序,你可以創建一個快捷方式文件,使用所需的命令行選項啓動應用程序。

的快捷方式文件的格式如下:

[number of ASCII characters after pound sign allocated to command-line arguments]#[command line] [optional parameters]

例如:

40#\Windows\MyApp.exe parameter1 parameter2

見:http://msdn.microsoft.com/en-us/library/ms861519.aspx