Jump to content

need help with StdinWrite and StdoutRead ...


Recommended Posts

Hi all,

i'm tryin to automate a data exchange between my autoit Script and a dos process running in the background. i use an executable called "cs2cs" which is a GIS tool used to convert x-y coordinate between various geographical systems. i enter "C:\OSGeo4W\bin\cs2cs -I +init=d:\IGNF:LAMBE +to +init=d:\IGNF:LAMB93" at the dos prompt and then the programm keep running waiting for x y coordinates to be entered (with a white space separator). The program ends when a ctrl-z is entered.

here is what i'm doing with autoIt :

$Command=@ComSpec & " /c " & "C:\OSGeo4W\bin\cs2cs -I +init=d:\IGNF:LAMBE +to +init=d:\IGNF:LAMB93"

$foo=Run($ChaineCommande, "", @SW_HIDE,$STDIN_CHILD  + $STDOUT_CHILD)

StdinWrite($foo, "619119.460 7102502.980" & @CR)
StdinWrite($foo)

Local $line
;While 1
    $line = StdoutRead($foo)
    ;If @error Then ExitLoop
    MsgBox(0, "test 1 :", $line)
;Wend

StdinWrite($foo, "619119.460 7102502.980" & @CR)
$line = StdoutRead($foo)
MsgBox(0, "test 2 :", $line)

StdinWrite($foo)

StdinWrite($foo, "619119.460 7102502.980" & @CR)
$line = StdoutRead($foo)
MsgBox(0, "test 3 :", $line)

StdinWrite($foo, "619119.460 7102502.980" & @CR)
$line = StdoutRead($foo)
MsgBox(0, "test 4 :", $line)

among these 4 tries (msgbox lines) only test 2 succeeds ... can anybody explain me why ?

If i uncomment the while/wend loop it seems the programm never gets out of it ...

I would like to convert heaps of x-y coordinates so i would like this batch conversion to work.

Thanks for ur help !

Edited by snaileater
Link to comment
Share on other sites

I've found recently that the best approach is to create a function handling StdinWrite and StdoutRead.

I can't test if it is working or not but for me it works with other applications so I guess it will be OK.

$Command=@ComSpec & " /c " & "C:\OSGeo4W\bin\cs2cs -I +init=d:\IGNF:LAMBE +to +init=d:\IGNF:LAMB93"

$foo=Run($ChaineCommande, "", @SW_HIDE,$STDERR_MERGED + $STDIN_CHILD)

$res = _SendCommand("619119.460 7102502.980")
MsgBox(0, "result", $res)


Func _SendCommand($cmd)
    StdinWrite($foo, $cmd & @CRLF)
    Sleep(300)
    Local $ResponseText
    While 1
        Sleep(50)
        $ResponseText &= StdoutRead($foo)
        If @extended = 0 Then ExitLoop
    Wend
    Return $ResponseText
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Thanks for answering ...

i tried your solution with this _sendCommand but i don't get anything better. When i send x-y coordinates such as :

$res = _SendCommand("619119.460 7102502.980")

i only get blank strings as answers.

when i make a wrong intialization of the executable by providing wrong pathes in the following line :

C:\ms4w\proj\bin\cs2cs -I +init=c:\IGNF:LAMBE +to +init=c:\IGNF:LAMB93

i get an error message showing that the dialog between the autoitssript and the dos command is set, but then when sending x-y data i don't see any improvement.

I don't understand...

Edited by snaileater
Link to comment
Share on other sites

From my point of view my code handles the successful communication via StdinWrite and StdoutRead.

Why are you getting nothing as a result? I can't know that; have you tried the same commands in a cmd window and it returned what you expected?

I really doubt that anyone is able to help you (download cs2cs, read docs, build test example and take time to figure how the application need to be handled) because it is simply too much work involved.

My advice - you should really spend some time working more with cs2cs; try the things you want to automate first in a normal cmd window and after that make your script to replicate what you have done - that's your homework.

Good luck,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I would test your script with a normal dos command first (im sure enaiman's will work) then go from there. In my experience its always something simple. I would also recommend using additional single quotes around your string parameters.

Good luck :)

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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