Sign in to follow this  
Followers 0
myspacee

Capture value returned from DOS command

16 posts in this topic

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

But, I would use the "Date" functions for the date or time

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

triky one, not tried yet, but sure works :)

m.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

forgot to post also solution:

dos command  2> yourfile.txt

' 2> ' do the trick.

m.

Share this post


Link to post
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 :)

Share this post


Link to post
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.

Share this post


Link to post
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 :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Then always prepend and append a double quote to the path like:

Dim $Path = '"' & @ScriptDir & '\Something\some.thing"'

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