Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

how to capture dynamic text from cmd window?


  • Please log in to reply
2 replies to this topic

#1 Manjish

Manjish

    !!DT!!

  • Active Members
  • PipPipPipPipPipPip
  • 558 posts

Posted 23 January 2009 - 06:03 AM

Guys,
I am running the following command..

psexec \\<compname> -u <username> -p<password> <somefile.bat>


Somefile.bat is copied locally to the target m/c where i want to run it.
Now, what i want to do is get the result of the psexec command, whether it was successful or not. The typical successful result looks like this:

c:\somefile.bat exited on <compname> with error code 0.


fialure:
c:\somefile.bat exited on <compname> with error code 1.


I want to capture error code, which will tell me whether the psexec command executed properly or not.
I tried two things:

1) using stdoutread as:

$iStdoutg = Run(@comspec & ' /C psexec \\<compname> -u <user> -p ' &'"<password>"'& ' <path to bat file>' , @workingdir, _             @SW_HIDE, 6) sleep(4000) While 1 $line = StdoutRead($iStdoutg) MsgBox(1,"",$line) If @error Then ExitLoop If $line <> "" then FileWriteLine("c:\test.txt",$line) EndIf WEnd


2) using ">c:\test.txt" in cmd.

Run(@comspec & ' /C psexec \\<compname> -u <user> -p ' &'"<password>"'& ' <path to bat file> >c:\test.txt' , @workingdir, _             @SW_HIDE, 6)



But none of the above methods work. Please help.

Edited by Manjish, 23 January 2009 - 06:04 AM.

Posted ImageManjish NaikEngineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com







#2 fctd

fctd

    Seeker

  • Active Members
  • 48 posts

Posted 23 January 2009 - 06:32 AM

try this.

$iStdoutg = Run(@comspec & ' /C psexec \\<compname> -u <user> -p ' &'"<password>"'& ' <path to bat file>' , @workingdir, _             @SW_HIDE, 6) sleep(4000) While 1     $line = StdoutRead($iStdoutg)       If @error Then ExitLoop     MsgBox(1,"First Message",$line) ;   If $line <> "" then ;       FileWriteLine("c:\test.txt",$line) ;   EndIf WEnd While 1     $line = StderrRead($iStdoutg)     If @error Then ExitLoop     MsgBox(0, "STDERR read:", $line) Wend


Will you get the text in the MsgBox?
If nothing is certain, everything is possible.Experience is something you get, just after you need it.

#3 Manjish

Manjish

    !!DT!!

  • Active Members
  • PipPipPipPipPipPip
  • 558 posts

Posted 23 January 2009 - 06:47 AM

try this.

$iStdoutg = Run(@comspec & ' /C psexec \\<compname> -u <user> -p ' &'"<password>"'& ' <path to bat file>' , @workingdir, _             @SW_HIDE, 6) sleep(4000) While 1     $line = StdoutRead($iStdoutg)       If @error Then ExitLoop     MsgBox(1,"First Message",$line) ;   If $line <> "" then ;       FileWriteLine("c:\test.txt",$line) ;   EndIf WEnd While 1     $line = StderrRead($iStdoutg)     If @error Then ExitLoop     MsgBox(0, "STDERR read:", $line) Wend


Will you get the text in the MsgBox?

Perfect.. exactly what i needed.
I can now search within the string $line for the line with the error code 0 or 1 to und exactly whether psexec run was successful or not.
Here's the slight modification i made:

$iStdoutg = Run(@comspec & ' /C psexec \\<compname> -u <user> -p ' &'"<pass>"'& ' <path to bat file>' , @workingdir, _             @SW_HIDE, 6) sleep(4000) While 1     $line = StderrRead($iStdoutg)     If @error Then ExitLoop     $str="with error code 0."     $a=StringInStr($line,$str)     if $a=0 then msgbox(4096,"","error") Wend


Thanks.. FCTD
Posted ImageManjish NaikEngineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users