• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

How to create a script to run a command, capture output, run through if statement?

I need a simple script created that will run a custom command (dfc get /isfrozen), return a value (either THAWED or FROZEN), and run through an if statement that will give me a 0 for thawed and a 1 for frozen.  If anyone could help me out that would be greatly appreciated.
0
khdonabergerwidener
Asked:
khdonabergerwidener
  • 2
  • 2
2 Solutions
 
oBdACommented:
Something like this?
dfc get /isfrozen | find /i "THAWED" >NUL
if not errorlevel 1 (echo 0) else (echo 1)

Open in new window

0
 
khdonabergerwidenerAuthor Commented:
I need it to return a value to an external source, in this case, ZCM 11.  When I run that it just echo's the entire thing like so:

C:\dfc get /isfrozen     | find /i "THAWED"   1>NUL
C:\if not errorlevel 1 (echo 0 )  else (echo 1 )
1

C:\

I ran this on both a thawed machine and a frozen machine and they're both returning 1.
0
 
oBdACommented:
You need to be more precise in your description. What you wrote sounded like "dfc get /isfrozen" would return either THAWED or FROZEN.
And what exactly do you mean with "return a value to an external source"? Return a certain errorlevel, echo out a certain string, call another program with certain arguments depending on the result of dfc?
I just had a look at the dfc documentation; dfc will actually return errorlevel 1 if the machine is "frozen".
@echo off
dfc get /isfrozen
set Frozen=%ErrorLevel%
REM The variable Frozen is now 1 if the machine is frozen, 0 if it is thawed.
echo Frozen: %Frozen%

Open in new window

0
 
BillDLCommented:
khdonabergerwidener

This PDF file tells you the 5 Exit Codes for DFC and provides the rough layout of a batch file that would allow you to inser your own custom command in the appropriate place that it jumps to using GOTO:

http://www.faronics.com/whitepapers/df_remoteadministration.pdf

When you run a command in most cases an Exit Code of Zero is normally a success, whereas a 1 or greater signifies an error, warning, etc.  However, if you look at the "Return Values" of the above PDF document you will see that it refers to "Boolean".  The word "Boolean" just means a test that returns a Truie or False to a question.  So, with your     DFC /IsFrozen     command you are asking Faronics DeepFreeze "Is this computer frozen, True or False, Yes or No, Give me a 1 or 0?", to which it replies "True" with a "1" or False with a "0".

There should be no reason to swap the Return Codes around and make a 1 into a 0 and a 0 into a 1, unless you really must call another program with a 1 or 0 as the parameter where the numbers mean different things to that program.

You don't have to test all the Exit Codes all of the time as shown in the example batch file at the bottom of the PDF document.  If you just wanted to check if a machine is "frozen", and force a reboot to the "thawed" state if it is, then you just need to ask if it's frozen and listen out for a "1", or else just ignore it, like this basic example:

@echo off
dfc get /isfrozen
if %errorlevel% equ 1 dfc /BootThawed
0
 
BillDLCommented:
Thank you khdonabergerwidener
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now