Jump to content

Capture value returned from DOS command


myspacee
 Share

Recommended Posts

hello to all,

in these days i'm working on comparing images,

all fine at this point, but now i've possibility to exapand my results.

Lot of DOS programs return a value after finish its work

RunWait(@ComSpec & " /c " & "date /T")

return today date without prompting user anything else.

is possibile to capture date in code post above ?

thank you for info,

m.

Link to comment
Share on other sites

look at consolewrite

I don't think so....

StdoutRead() is what he wants

; Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")

8)

NEWHeader1.png

Link to comment
Share on other sites

Perfect !

thank you,

m.

EDIT:

speak too soon.

for Imagemagick command i must run command from runwait() and so it doesn't works:

(result ok but not console 'capture')

$IM_compare_A_vs_B = runwait(@ComSpec & " /c " & @ScriptDir & "compare -fuzz 95% -metric PSNR A.tif B.tif diff.png")

m.

Edited by myspacee
Link to comment
Share on other sites

looks like your missing the exe file name and a \ for example

$IM_compare_A_vs_B = runwait(@ComSpec & " /c " & @ScriptDir & "\Imagemagick compare -fuzz 95% -metric PSNR A.tif B.tif diff.png")

thats assuming the Imagemagick program is called Imagemagick and that it is in the same dir as the script.

also not sure if it works with runwait i normally use something like

$IM_compare_A_vs_B = run(@ComSpec & " /c " & @ScriptDir & "\Imagemagick compare -fuzz 95% -metric PSNR A.tif B.tif diff.png")

While ProcessExists($IM_compare_A_vs_:)

Sleep(100)

$Read = StdoutRead($IM_compare_A_vs_B, True)

WEnd

msgbox(0,'',$read)

Edited by Onichan
Link to comment
Share on other sites

sorry oni,

'compare' is one imagemagick executables.

Result of command is ok, can't capture STDOUT.

runwait() is problem for me can't use $STDERR_CHILD + $STDOUT_CHILD as parameters...

(i believe)

m.

Edited by myspacee
Link to comment
Share on other sites

Try this:

#include <Process.au3>

;~ Example
MsgBox(0,"",DOSResult("VER"))
MsgBox(0,"",DOSResult("dir c:"))

Func DOSResult($LINE)
    _RunDOS($LINE & " >" & @TempDir & "\DosResult.txt")
    $FILE = FileOpen(@TempDir & "\DosResult.txt",0)
    $RESULT = FileRead($FILE)
    FileClose($FILE)
    Return $RESULT
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

  • 1 month later...

Try this:

#include <Process.au3>

;~ Example
MsgBox(0,"",DOSResult("VER"))
MsgBox(0,"",DOSResult("dir c:"))

Func DOSResult($LINE)
    _RunDOS($LINE & " >" & @TempDir & "\DosResult.txt")
    $FILE = FileOpen(@TempDir & "\DosResult.txt",0)
    $RESULT = FileRead($FILE)
    FileClose($FILE)
    Return $RESULT
EndFunc

it doesn't work.

here is my script

#include <Process.au3>

;~ Example

MsgBox(0,"",DOSResult("compare -metric PSNR c:/0.jpg c:/1.jpg c:/difference.png"))

Func DOSResult($LINE)

_RunDOS($LINE & " >" & @TempDir & "\DosResult.txt")

$FILE = FileOpen(@TempDir & "\DosResult.txt",0)

$RESULT = FileRead($FILE)

FileClose($FILE)

Return $RESULT

EndFunc

it popup nothing on msgbox. (and in the DosResult.txt too.)

can someone help?

thank you :)

Edited by slideawayz
Link to comment
Share on other sites

thank you myspacee

but I still no luck with this. when I run script, I got

Posted Image

and this command work fine in cmd

Posted Image

here is my script

#include <Process.au3>

;~ Example
MsgBox(0,"",DOSResult("compare -metric PSNR c:/0.jpg c:/1.jpg c:/difference.png"))

Func DOSResult($LINE)
_RunDOS($LINE & " 2>" & @TempDir & "\DosResult.txt")
$FILE = FileOpen(@TempDir & "\DosResult.txt",0)
$RESULT = FileRead($FILE)
FileClose($FILE)
Return $RESULT
EndFunc

any help will be greatly appreciated :)

Link to comment
Share on other sites

#include <Process.au3>

;~ Example
MsgBox(0,"",DOSResult("compare -metric PSNR c:/0.jpg c:/1.jpg c:/difference.png"))

Func DOSResult($LINE)
_RunDOS($LINE & " > " & @TempDir & "\DosResult.txt") ;==> Did you take into consideration the working path?
$FILE = FileOpen(@TempDir & "\DosResult.txt",0)
$RESULT = FileRead($FILE)
FileClose($FILE)
Return $RESULT
EndFunc

If compare should be in the working directory then $LINE probably is correct otherwise it should contain "Path with blanks\compare.exe" for example. Don't forget the double quotes to enclose the path in a valid form.

Link to comment
Share on other sites

#include <Process.au3>

;~ Example
MsgBox(0,"",DOSResult("compare -metric PSNR c:/0.jpg c:/1.jpg c:/difference.png"))

Func DOSResult($LINE)
_RunDOS($LINE & " > " & @TempDir & "\DosResult.txt") ;==> Did you take into consideration the working path?
$FILE = FileOpen(@TempDir & "\DosResult.txt",0)
$RESULT = FileRead($FILE)
FileClose($FILE)
Return $RESULT
EndFunc

If compare should be in the working directory then $LINE probably is correct otherwise it should contain "Path with blanks\compare.exe" for example. Don't forget the double quotes to enclose the path in a valid form.

Thank You Authenticity :)

now it working.

thank you very much :)

Link to comment
Share on other sites

ok I got this to work

but when my script directory have space in the path name, script will not wotk.

Posted Image

my script

#include <Process.au3>

;~ Example

MsgBox(0,"",DOSResult(@ScriptDir & "\comparer\compare.exe -fuzz 5% c:/0.jpg c:/1.jpg c:/difference.png"))

Func DOSResult($LINE)

_RunDOS($LINE & " 2> " & @TempDir & "\DosResult.txt") ;==> Did you take into consideration the working path?

$FILE = FileOpen(@TempDir & "\DosResult.txt",0)

$RESULT = FileRead($FILE)

FileClose($FILE)

Return $RESULT

EndFunc

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...