Sign in to follow this  
Followers 0

how to capture dynamic text from cmd window?

3 posts in this topic

#1 ·  Posted (edited)

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

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites



#2 ·  Posted

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?


[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted

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


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0