MBC Computer Solutions Ltd.

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 13 August 2007

Assigning an programs output to a variable in a batch file

Posted on 17:46 by Unknown
This one took me longer than it should have to figure out. I had to write a batch file to integrate with our monitoring appliance - I can't really remember the last time I had to do this, but the number 6.22 comes to mind.

Anyways, the goal was to set a variable's value to the output (note: note the exit code) to the variable. You can't do this with the SET command so I had to result to using the FOR statement.

From a command prompt, it looks like:

for /f "tokens=*" %a in ('Program.exe "argument1"') do set __VARIABLENAME__=%a

Only one gotcha - in a batch file, you need to double up your % identifiers.

REM This is the start of the batch file
for /f "tokens=*" %%a in ('Program.exe "argument1"') do set __VARIABLENAME__=%%a
echo Result is %__VARIABLENAME__%
REM This is the end of the batch file

I'm glad thats over, back to C# for me!
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

Blog Archive

  • ►  2012 (1)
    • ►  February (1)
  • ►  2010 (1)
    • ►  April (1)
  • ►  2009 (7)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  July (1)
    • ►  April (2)
    • ►  February (1)
  • ►  2008 (36)
    • ►  November (3)
    • ►  October (2)
    • ►  September (1)
    • ►  August (1)
    • ►  July (2)
    • ►  June (6)
    • ►  May (4)
    • ►  April (1)
    • ►  March (4)
    • ►  February (7)
    • ►  January (5)
  • ▼  2007 (35)
    • ►  December (1)
    • ►  November (9)
    • ►  October (3)
    • ►  September (6)
    • ▼  August (7)
      • Yes, you can use C# controls in VB.NET code
      • Blackberry 8800 software update - where are you?
      • C# ? operator - Nullable shorthand
      • Assigning an programs output to a variable in a ba...
      • System.Net.WebException from XmlDocument.Load
      • Choosing appropriate field lengths
      • Why don't things just work in Safari?!
    • ►  July (9)
  • ►  2006 (3)
    • ►  May (3)
Powered by Blogger.

About Me

Unknown
View my complete profile