Shoutbox

Capture output of launched external application? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Capture output of launched external application? (/showthread.php?tid=69097)

Capture output of launched external application? by V@no on 12-03-2006 at 09:07 AM

Hello!
I'm trying launch an external program via MP!L script. So far I found only one way to do so:

code:
  var objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute('C:\\myprogram.exe', '', '', "open", 0);

myprogram.exe returns some text which I need to capture. unfortunetly ShellExecute only returns error codes or such...
Is there a way launch an external application (with no window showed if possible) and capture the output?

Thank you.

P.S. I dont know advanced programming languages such as C or even VB...
RE: Capture output of launched external application? by Eljay on 12-03-2006 at 09:13 AM

code:
var Shell = new ActiveXObject('WScript.Shell');
var oExec = Shell.Exec("C:\\myprogram.exe");
Debug.Trace(oExec.StdOut.ReadAll());

RE: Capture output of launched external application? by V@no on 12-03-2006 at 09:59 AM

Yes, that's it, very good.
Now, if I could get rid off the command prompt window it would be perfect!

Thanks


RE: Capture output of launched external application? by Spunky on 12-03-2006 at 01:59 PM

quote:
Originally posted by V@no
Now, if I could get rid off the command prompt window it would be perfect!

I think it might be possible to iterate through open windows, get the handle to the command prompt and hide/close it
RE: Capture output of launched external application? by V@no on 12-04-2006 at 02:12 AM

yes, I've tryed that, but again, with "open" I can not capture the output...


RE: Capture output of launched external application? by V@no on 12-05-2006 at 03:17 AM

I found a work around this...I'm using "open" instead of "exec", that allowes to run hidden command prompt window.
then I created a myprogram.bat file where I set command line to execute my program and redirect output into a file:

code:
C:\myprogram.exe > C:\output.txt
and finaly I read the output file in the script.

Somebody might find this is useful, here is the script code:
code:
var outputfile = "C:\\output.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var Shell = new ActiveXObject('WScript.Shell');
var oExec = Shell.Run("C:\\myprogram.bat", 0, true);
var output = "";
if(fso.FileExists(outputfile))
  output = fso.OpenTextFile(outputfile, 1, true, 0).fH.ReadAll();