Jump to content

StdoutRead


fielmann
 Share

Recommended Posts

Under consolewrite everything is ok :)

Can anbody tell me why the Messagebox has no content as result? ;)B)

$cmd = "compare -metric RMSE BFF.JPG b.png delta.png"
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid,1)
  If @error Then ExitLoop
  $text &= $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result",$text)

Where is the prob? B)

Link to comment
Share on other sites

Sorry bro i dont know english ver well but try may be it help to you. and i`m too newbie in this programming language .

; Script Start - Add your code below here
$cmd = "cmd.exe /c COMP b.png delta.png /D  & pause"   ; this is my test command change it to yours
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid,1)
  If @error Then ExitLoop
  $text = $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result", $text())
[size="5"] [/size]
Link to comment
Share on other sites

  • Developers

Under consolewrite everything is ok :)

Can anbody tell me why the Messagebox has no content as result? ;)B)

$cmd = "compare -metric RMSE BFF.JPG b.png delta.png"
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid,1)
  If @error Then ExitLoop
  $text &= $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result",$text)

Where is the prob? B)

Script looks good at first glans. Maybe too many CRLFs ?

How did the ConsoleWrite output look?

Sorry bro i dont know english ver well but try may be it help to you. and i`m too newbie in this programming language .

; Script Start - Add your code below here
$cmd = "cmd.exe /c COMP b.png delta.png /D  & pause"   ; this is my test command change it to yours
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid,1)
  If @error Then ExitLoop
  $text = $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result", $text())

$Text() ? doubt that.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Under consolewrite everything is ok :)

Can anbody tell me why the Messagebox has no content as result? ;)B)

$cmd = "compare -metric RMSE BFF.JPG b.png delta.png"
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid,1)
  If @error Then ExitLoop
  $text &= $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result",$text)

Where is the prob? B)

It works fine when you substitute a known working command:
$cmd = "tasklist.exe"
$pid = Run($cmd, @ScriptDir, @SW_hide, "0x2")
$text = ""
While ProcessExists($pid)
  $line = StdoutRead($pid, 1)
  If @error Then ExitLoop
  $text &= $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result", $text, 5)

But that also demonstrates a problem in using peek mode (why did you use that?). If it takes more than one pass through the loop to get all the data you wind up with duplicate copies because of the "&=" append operator. You should drop the peek flag on StdOutRead().

If there is a problem with your command line, run it this way to see what's happening:

$cmd = "compare -metric RMSE BFF.JPG b.png delta.png"
$pid = Run(@ComSpec & " /k " & $cmd, @ScriptDir, @SW_SHOW)
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thx all for researching where the problem is! :)

I still try to get the result of the folowing command into a Messagebox:

$cmd = "compare -metric RMSE c:\pics\1st.JPG c:\pics\2nd.JPG c:\pics\delta.jpg"

SCITE-Console shows the correct result: ;)

>"C:\Programme\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Dokumente und Einstellungen\administrator\Desktop\Neu AutoIt v3 Script.au3"

505.15 (0.0077081) @ 73,61

>Exit code: 0 Time: 26.572

$pid = Run(@ComSpec & " /k " & $cmd, @ScriptDir, @SW_SHOW)

DOS-BOX also shows the correct result: 505.15 (0.0077081) @ 73,61 B)

B) But I still have the problem that the message leaves blank B)

But where is the problem? B)

Edited by fielmann
Link to comment
Share on other sites

I've tested a little bit more :)

The script doesn't wait before the Command is finished ;)

It seems that "while ProcessExists" doesn't work correctly B)

Any ideas how to solve?

Hi,

try While 1 instead of While ProcessExists. The loop will end automatically, because of If @error Then ExitLoop.

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

try While 1 instead of While ProcessExists. The loop will end automatically, because of If @error Then ExitLoop.

;-))

Stefan

I've changed the source:

$text = ""
$cmd = "compare -metric RMSE c:\pics\1st.JPG c:\pics\2nd.JPG c:\pics\delta.jpg"
$pid = Run(@ComSpec & " /k " & $cmd, @ScriptDir, @SW_SHOW)
While 1
  $line = StdoutRead($pid,1)
  If @error Then 
    MsgBox(0,"Error","Error")
    ExitLoop
  EndIf
  $text &= $line
  ConsoleWrite($line)
Wend
MsgBox(0,"Result",$text)

But now the While-Loop goes on "Error" before the DOS-Box has finished its work :)

Edited by fielmann
Link to comment
Share on other sites

The debug code I posted was intended to run stand alone, without the loop, displaying to the console window (which remains open) so you could verify the command worked correctly. There is no child output flag for Run(), so StdOutRead() fails immediately.

By the way, if you have set $STDOUT_CHILD and the output still shows up in the SciTE console when you run it, then it may be coming from STDERR, not STDOUT. Change the flag to $STDOUT_CHILD + $STDERR_CHILD, and do both StdOutRead() and StdErrRead().

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The debug code I posted was intended to run stand alone, without the loop, displaying to the console window (which remains open) so you could verify the command worked correctly. There is no child output flag for Run(), so StdOutRead() fails immediately.

I already posted the wanted info ;) look @:

[...]

$pid = Run(@ComSpec & " /k " & $cmd, @ScriptDir, @SW_SHOW)

DOS-BOX also shows the correct result: 505.15 (0.0077081) @ 73,61 :)

Link to comment
Share on other sites

I already posted the wanted info ;) look @:

Got that, but you didn't put the child flag back when trying to use it with StdOutRead() in post #9.

In the console, you can't tell the difference between STDOUT and STDERR. I was proposing that the app you are using might be outputting via STDERR, which would explain seeing it on the console but not with StdOutRead(). Try using both StdOutRead() and StdErrRead() as suggested earlier.

:)

Edit: Typo.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Got that, but you didn't put the child flag back when trying to use it with StdOutRead() in post #9.

In the console, you can't tell the difference between STDOUT and STDERR. I was proposing that the app you are using might be outputting via STDERR, which would explain seeing it on the console but on with StdOutRead(). Try using both StdOutRead() and StdErrRead() as suggested earlier.

B)

Here we go:

#include <Constants.au3>
$cmd = "compare -metric RMSE c:\pics\1st.JPG c:\pics\2nd.JPG c:\pics\delta.jpg"
Local $foo = Run(@ComSpec & " /c " & $cmd, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    ConsoleWrite($line)
    if not $line="" then 
        ;MsgBox(0, "STDERR read:", $line,5)
        $Result = $line
    EndIf
Wend
MsgBox(0, "Compare-Result", $Result)

Now it works! ;)

THX PsaltyDS you gave the important tip :)

Link to comment
Share on other sites

That may get exactly what you need in this situation, only the last output from STDERR only, but I usually like reading both STDOUT and STDERR to get ALL the output. So for possible future reference:

#include <Constants.au3>

Local $cmd = "compare -metric RMSE c:\pics\1st.JPG c:\pics\2nd.JPG c:\pics\delta.jpg"
Local $foo = Run(@ComSpec & " /c " & $cmd, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $iError, $line, $Result = ""
While 1
    $line = StdOutRead($foo)
    $iError = @error

    $line &= StdErrRead($foo)
    $iError += @error
    
    If StringStripWS($line, 8) <> "" Then $Result &= $line

    If $iError Then ExitLoop

    Sleep(10)
Wend
MsgBox(0, "Compare-Result", $Result)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...