Tar*_*sov 10 c# xml binary batch-file bin
嗨我对c#和批处理文件有疑问.我想执行批处理命令并将输出保存在c#中的字符串中.但我只能执行该文件,但不能将此内容保存在字符串中,并在文本框中显示.
我的批处理文件:
@echo关闭
"C:\ lmxendutil.exe"-licstatxml -host serv005 -port 6200> C:\ Temp\HW_Lic_XML.xml notepad C:\ Temp\HW_Lic_XML.xml
这是我的c#代码:
private void btnShowLicstate_Click(object sender, EventArgs e)
{
string command = "'C:\\lmxendutil.exe' -licstatxml -host lwserv005 -port 6200";
txtOutput.Text = ExecuteCommand(command);
}
static string ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
exitCode = process.ExitCode;
process.Close();
return output;
}
Run Code Online (Sandbox Code Playgroud)
我想输出ia stirng,如果我能做到这一点,我希望我没有批处理文件.我想直接在c#中执行这个batvchcommand ...我可以这样做吗?
不需要使用"CMD.exe"执行命令行应用程序或检索输出,可以直接使用"lmxendutil.exe".
试试这个:
processInfo = new ProcessStartInfo();
processInfo.FileName = "C:\\lmxendutil.exe";
processInfo.Arguments = "-licstatxml -host serv005 -port 6200";
//etc...
Run Code Online (Sandbox Code Playgroud)
做你的修改以在那里使用"命令".
我希望这有帮助.
| 归档时间: |
|
| 查看次数: |
13602 次 |
| 最近记录: |