Reading output from command line pogram.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Reading output from command line pogram.

Post by rullbandspelare » Sun Mar 28, 2010 9:30 am

Hi!
Is it possible to read the output from a command line program directly into a variable?
And not like this:
Run Program>cmd /c "dir >c:\dirout.txt"
ReadFile>c:\dirout.txt,dirout
This is what I do now (the dir command is jus an example.)

I.e
the output from
Run Program>cmd /c "dir"
is directly read by MS into the variable dirout.

That would be helpful!

Thanks!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Mar 29, 2010 7:05 am

Hi,

No. The only thing I can think of is to have a .bat file redirect stdout to a file, read the file into a variable and than pass the content of that to Macro Scheduler on the command line.

But that's probably no less work than outputting to a file and having your macro read the file. Just depends at which end you want to do the work.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Mar 30, 2010 4:06 am

Just curious about why? Are you trying to avoid writing a file that may need to be deleted or moved? Trying to make sure that there is no trace left behind? There may be ways to accomplish that without creating a file or leaving a trail.

Can you explain why the need, what you are trying to accomplish with this methodology? One extra line in a script does not seem to be a big penalty.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Tue Mar 30, 2010 4:29 am

Hi!
I need to run a third party command line program and get the output from that program into the script

1. It is a multi user program. I.e it is NOT run on a single PC. It is run from a webpage. So if two users use the same function and one creates the file at the same time as someone else is deleting it, You have problem. (as it is now i create unique filenames)

2. Writing to a file slows things down. It is faster to write directly to RAM.

Thanks for Your interest!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Found the answer

Post by adroege » Mon Apr 26, 2010 3:11 pm

Try this.

Code: Select all

VBSTART
Function GetIn()

  Dim WshShell, oExec, input
  Set WshShell = CreateObject("WScript.Shell")
  Set oExec    = WshShell.Exec("cmd /c dir")
  input = ""

  Do While True
     If Not oExec.StdOut.AtEndOfStream Then
          input = input & oExec.StdOut.Read(1)
          If oExec.StdOut.AtEndOfStream Then Exit Do
     End If
  Loop

  GetIn = input
End Function
VBEND

VBEval>GetIn,result
MessageModal>result

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Mon Apr 26, 2010 9:43 pm

This works very well!

Thanks a million.
You just made my coding a lot easier!!!!

THANKS!!!!

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Thu Jul 21, 2011 8:43 am

Hi again!

I have two followups on the code.

1. Is it possible to hide the CMD window? I have tried with RP_WINDOWMODE=0, but that does not work

2. If the cmd argument does not result in an output, the application hangs. Any idea on how to prevent this?

Thanks!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts