running from command prompt

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,
I am writing a program, and need to execute a part of it in command
prompt.

When I execute it in command prompt, I type the following
c:\> id3tag.exe music.wma show
and it returns for me an XML file.

How can I do that in C#. I was trying to do that by using the Process
object but got lost.


Thanks in Advance
 
Xarky said:
I am writing a program, and need to execute a part of it in command
prompt.

When I execute it in command prompt, I type the following
c:\> id3tag.exe music.wma show
and it returns for me an XML file.

How can I do that in C#. I was trying to do that by using the Process
object but got lost.

Well, how far have you got? You definitely need to use Process, and
possibly ProcessStartInfo.
 
Hi,
I was trying the following

Process wmaProcess = new Process();
string filePath, musicPath, xmlFile;

// contains the path for the program to be executed
filePath = Application.StartupPath+@"\id3tag.exe";
// contains the path for the music file
musicPath = this.musicPath + "\\" + this.musicName;
wmaProcess.StartInfo.FileName = filePath;
wmaProcess.StartInfo.Arguments = musicPath+" show";
wmaProcess.StartInfo.CreateNoWindow = true;
wmaProcess.StartInfo.UseShellExecute = false;
wmaProcess.Start();
wmaProcess.WaitForExit();
xmlFile = wmaProcess.StandardOutput.ReadToEnd();

My program is failing on the last line. It is giving me the following
error -

An unhandled exception of type 'System.InvalidOperationException'
occurred in system.dll

Additional information: StandardError has not been redirected.
 
xarky said:
I was trying the following

Process wmaProcess = new Process();
string filePath, musicPath, xmlFile;

// contains the path for the program to be executed
filePath = Application.StartupPath+@"\id3tag.exe";
// contains the path for the music file
musicPath = this.musicPath + "\\" + this.musicName;
wmaProcess.StartInfo.FileName = filePath;
wmaProcess.StartInfo.Arguments = musicPath+" show";
wmaProcess.StartInfo.CreateNoWindow = true;
wmaProcess.StartInfo.UseShellExecute = false;
wmaProcess.Start();
wmaProcess.WaitForExit();
xmlFile = wmaProcess.StandardOutput.ReadToEnd();

My program is failing on the last line. It is giving me the following
error -

An unhandled exception of type 'System.InvalidOperationException'
occurred in system.dll

Additional information: StandardError has not been redirected.

Are you sure it's not saying that StandardOutput has not been
redirected? Either way, if you're going to try to read from
StandardOutput, then:

a) You should be reading from it *before* your call to WaitForExit,
otherwise the buffer might end up being blocked

b) You must tell the StartInfo to redirect standard output.
 
Back
Top