Home > Archive > VC Language > January 2006 > Running external program and capture output Shellexecute?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Running external program and capture output Shellexecute?
|
|
| Marcel 2006-01-25, 7:23 pm |
| 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?
I tried to use ShellExecute, but I couldn't get it to work.
Kind regards,
Marcel
| |
| Jochen Kalmbach [MVP] 2006-01-25, 7:23 pm |
| 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/
| |
|
|
| Marcel 2006-01-30, 8:02 am |
| 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@holzma.de]
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/
|
|
|
|
|