使用cmd.exe发出执行命令 [英] Issue executing a command with cmd.exe

查看:177
本文介绍了使用cmd.exe发出执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到执行此代码的问题:

I've got an issue executing this code:

Process arp = new Process();
arp.StartInfo.UseShellExecute = false;
arp.StartInfo.RedirectStandardOutput = true;
arp.StartInfo.FileName = "C://Windows//System32//cmd.exe";
arp.StartInfo.Arguments = "arp -a";
arp.StartInfo.RedirectStandardOutput = true;
arp.Start();
arp.WaitForExit();
string output = arp.StandardOutput.ReadToEnd();
MessageBox.Show(output);

程序应该将arp-a的输出放入String输出, :

The program should put the output of arp-a into the String output but it gives me back this instead:


Microsoft Windows [版本6.1.7601] \r\\\
Copyright(c)2009 Microsoft Corporation。保留所有权利。\r\\\
\r\\\
C:\Users\user01\documents\visual studio 2012\Projects\freehotspotexploiter\freehotspotexploiter\bin\Debug>

Microsoft Windows [Version 6.1.7601]\r\nCopyright (c) 2009 Microsoft Corporation. All rights reserved.\r\n\r\nC:\Users\user01\documents\visual studio 2012\Projects\freehotspotexploiter\freehotspotexploiter\bin\Debug>

有人知道如何修复它?

推荐答案

p>为了向cmd.exe发送命令作为参数,使用/ c标志。

In order to send a command to cmd.exe as an argument, use the "/c" flag.

arp.StartInfo.Arguments = "/c arp -a";

这篇关于使用cmd.exe发出执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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