0
votes

This question has been asked before but I think , the examples have been confusing a bit . Here's my situation :

Script : Python Location : On windows machine "C:\Users\Somedomain\Desktop\Temp\test.py"

Test.py looks like this:

def Fun1(t):
    import time
    print t.capitalize()
    time.sleep(5)
    return t.capitalize()

if __name__ == "__main__":
    Fun1('arindam')

I can run it from cmd prompt (Ctrl+R), then paste: python C:\Users\inchowar\Desktop\Temp\test.py

AUtoIt Script looks like:

#include <Constants.au3>
$temp = MyFun1()
MsgBox(64, "Result", $temp)

Func MyFun1()
   Local $pid =  Run('python C:\Users\inchowar\Desktop\Temp\test.py')
   if ProcessExists($pid) Then
      MsgBox(64, 'Result', 'Its Works..Till here')
      $var = StdoutRead($pid)
      MsgBox(64, 'Result', $var)
   EndIf
   ProcessClose($pid)
EndFunc

What i am trying to do here :

I want the output "Arindam" in that MsgBox showing $var .

With the above script , the python script runs , shows output on the shell , then the Main MsgBox shows blank . The 1st msgbox does gets showed up as it pops up successfully , proving that the pid indeed exists.

1

1 Answers

0
votes

You are missing special flags in your RUN command, an a "Return" in order for function to return a value. If the test.py runs indefinitely, then remove the while loop, but bare in mind that it needs to wait for some time in order to "catch" the console output.

#include <Constants.au3>
$temp = MyFun1()
MsgBox(64, "Result", $temp)

Func MyFun1()
   Local $pid =  Run('python C:\Users\inchowar\Desktop\Temp\test.py', @SW_HIDE, 

$STDERR_CHILD + $STDOUT_CHILD)
$var = ""
While 1
    $var &= StderrRead($pid)
    If @error Then ExitLoop
WEnd

   if $var <> "" Then
      MsgBox(64, 'Result', 'Its Works..Till here')
      MsgBox(64, 'Result', $var)
   EndIf

   ProcessClose($pid)
   Return $var
EndFunc