Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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 ....

C#
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);


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
Posted

Why are you using cmd to execute that? Why not execute it directly, capture the output as your code is doing already, and save that text yourself if you need to? Surely that is the easier way? All you need to them is put the path to your executable in the ProcessStartInfo instead of "cmd" and drop the DOS redirect.
 
Share this answer
 
why to use cmd ?

just use the following code. hope it will work fine.
string strCmdText="C:\\Program Files\\Veritas\\NetBackup\\Bin\\admincmd>bpdbjobs.exe>> e:\\ra.txt";
 System.Diagnostics.ProcessStartInfo procStartInfo =
                    new System.Diagnostics.ProcessStartInfo(strCmdText);
>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900