Re: Running external program and capture output Shellexecute?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

Jochen, your code worked for me only the rediriction of the output seems
to go wrong. When I run the program I want to call on the command prompt
output is created on the screen, but when I try to redirect it in the
way you suggest the output string remains empty.

I tried to redirect from StandardError, and I also tried to move the
WaitforExit to after the ReadToEnd clause, both without succes.

Any ideas on this?

Greetings,

Marcel



-----Original Message-----
From: Jochen Kalmbach [MVP] [mailto:nospam-Jochen.Kalmbach@xxxxxxxxx]
Posted At: woensdag 25 januari 2006 15:36
Posted To: microsoft.public.vc.language
Conversation: Running external program and capture output Shellexecute?
Subject: Re: Running external program and capture output Shellexecute?


Hi Marcel!

> Hi,
>
> I'm new here and I don't know if I'm posting this in the correct
place.
>
> I'm using Visual Studio 2003 and I have to create a windows
> application, so I use the .NET windows forms application to do this.
> My program has to use the Spin model checker, which I want to call as
> an external program. So I want to run that program in a dos-box from
> within my application and when it exits I want to read all the output
> it has generated to use in my application.
> Is there a way to do this?

If you do Windows-Forms you should also use the managed-API to do this
work...


#undef MessageBox

System::Diagnostics::ProcessStartInfo *si = new
System::Diagnostics::ProcessStartInfo();
si->UseShellExecute = false;
si->WorkingDirectory = S"C:\\";
si->FileName = "C:\\program.exe";
si->Arguments = "args";
si->RedirectStandardOutput = true;
System::Diagnostics::Process *p =
System::Diagnostics::Process::Start(si);
p->WaitForExit();
System::String *output = p->StandardOutput->ReadToEnd();
System::Windows::Forms::MessageBox::Show(output);


PS: A better newsgroup is
microsoft.public.dotnet.languages.vc

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

.



Relevant Pages

  • Some External Commands Wont Work Under Windows
    ... had no trouble with it (I'm using it on Linux and Windows 2K/XP). ... When the external program is called, ... When I finally exit the Java program by closing its Swing ... InputStream under Windows and the program would freeze after outputting one ...
    (comp.lang.java.help)
  • Re: New freeware: Jarx - the JAR executer
    ... >> There's no need for an external program. ... JAR files are set up to ... >I know Java is not installed on a lot of Windows XP computers. ...
    (comp.lang.java)
  • Re: New freeware: Jarx - the JAR executer
    ... >> There's no need for an external program. ... JAR files are set up to ... >I know Java is not installed on a lot of Windows XP computers. ...
    (comp.lang.java.softwaretools)
  • Re: VC++ Windows forms beginner question
    ... even in .Net Windows Forms everything runs in a while loop. ... this part was common between your directx application and the windows forms application. ... I need to call a function when a certain limit has been reached, now with the way VS sets up the .NET windows Form I get confused. ... it just confuses me because of the form.h and form.cpp and pretty much all there is ...
    (microsoft.public.dotnet.languages.vc)
  • Re: software will not install
    ... saying "windows cannot access the specified device, ... not have the appropriate permissions to access the item" or another says it ... "cannot execute the external program". ...
    (microsoft.public.windowsxp.general)