问题描述
大家好,
我在
中有一个EXE"C:\\ Program Files \\ Veritas \\ NetBackup \\ Bin \\ admincmd> bpdbjobs.exe"
它写一些文本输出...
现在,我需要获取输出文本并将其写入文本文件.为此,我正在使用此命令
"C:\\ Program Files \\ Veritas \\ NetBackup \\ Bin \\ admincmd> bpdbjobs.exe>> e:\\ ra.txt"
在命令提示符下运行良好.我正在使用此代码执行命令提示符,但无法正常工作....
Hello every one ,
I am having an EXE in
"C:\\Program Files\\Veritas\\NetBackup\\Bin\\admincmd>bpdbjobs.exe"
it writes some text output ...
Now i need to take that output text and write it into a text file . For that i am using this command
"C:\\Program Files\\Veritas\\NetBackup\\Bin\\admincmd>bpdbjobs.exe>> e:\\ra.txt"
It is working well in command prompt. I am using this code to execute the command prompt but it is not working ....
string strCmdText="C:\\Program Files\\Veritas\\NetBackup\\Bin\\admincmd>bpdbjobs.exe>> e:\\ra.txt";
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + strCmdText);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
MessageBox.Show(result);
上面显示的代码是在e驱动器中创建文件,但文本文件为空.
我正在C驱动器中运行我的windos应用程序,甚至在消息框中也为空.如果我写 strCmdText ="Md arun",则在我的应用程序的bin \ debug文件夹中创建文件夹 但是我想执行C驱动器中的命令,即使我复制了此项目要c驱动器无法正常工作...
所以任何人都可以建议一些链接或代码或提示.
预先感谢
the above code shown is creating a file in e drive but the text file is empty.
and i am running my windos application in C drive and even in message box is also empty . If I write strCmdText="Md arun" the folder in creating in bin\debug folder of my application But i want to execute command which is in C drive even if i copy this project to c drive it is not working...
so can anybody suggest some link or code or a hint .
Advance thanks
推荐答案
string strCmdText="C:\\Program Files\\Veritas\\NetBackup\\Bin\\admincmd>bpdbjobs.exe>> e:\\ra.txt";
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo(strCmdText);
>
这篇关于使用C#使用命令提示符(CMD)执行EXE文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!