Jump to content

Recommended Posts

Posted

Hello, I'm having a problem trying to write to my Python script.

I am perfectly able to receive output from Python, but I just can't seem to make an input!

Here is my code:

$Process = run("python io-test.py",@ScriptDir,@SW_HIDE,0x3)

ProcessWait("python.exe")

TrayTip("Success","Success!",10)

While 1
    StdinWrite($Process,"Hello, Python.")
    TrayTip("StdOut",StdoutRead($Process),10)
    Sleep(1000)
WEnd

while 1:
    string = input(">")
    print(string)

The tray tip, that should contain "Hello, Python.", only contains ">"! (which is the prompt from input(">"))

Someone please help, or I may cry.

Posted (edited)

When you Run() a process, the script pauses until the process has exited. So you're writing to a process that no longer exists. That's my initial thought anyway.

Run() is not a blocking function as you are suggesting. RunWait() behaves in the way you are describing.

Try this:

$Process = run("python io-test.py",@ScriptDir,@SW_SHOW,0x3)
ProcessWait("python.exe")
TrayTip("Success","Success!",10)
StdinWrite($Process,"Hello, Python.")
While 1
    $sLine = StdoutRead($Process)
    If @error Then ExitLoop
    TrayTip("StdOut", $sLine,10)
    Sleep(1000)
WEnd

Edit: Use @SW_SHOW so you can see whether the text is being written to the python console.

Edited by zorphnog
Posted (edited)

Try this:

$Process = run("python io-test.py",@ScriptDir,@SW_SHOW,0x3)
ProcessWait("python.exe")
TrayTip("Success","Success!",10)
StdinWrite($Process,"Hello, Python.")
While 1
    $sLine = StdoutRead($Process)
    If @error Then ExitLoop
    TrayTip("StdOut", $sLine,10)
    Sleep(1000)
WEnd

Edit: Use @SW_SHOW so you can see whether the text is being written to the python console.

Still only outputs ">". :-(

And the Python console isn't showing anything.

Edited by SirGarry32
Posted

python might be waiting for a @CRLF like c/c++ so try StdinWrite($Process,"Hello, Python." & @crlf)

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Posted (edited)

python might be waiting for a @CRLF like c/c++ so try StdinWrite($Process,"Hello, Python." & @crlf)

Oh my god, it works! I hate it when the solutions to my problems are so simple.

Thanks for the help guys.

Edited by SirGarry32

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
  • Recently Browsing   0 members

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