Jump to content

StdinWrite to Python doesn't work


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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