Since yesterday, i try to remote the console PYTHON without success

I have try numerous codes, but nothing really good

With this the stdout works (Thanks to the -i option of PYTHON) but how i can sending command ?
Code: Select all
CheminPython.s = "D:\pyzo2015a\"
NomPython.s = "python.exe"
p = RunProgram(CheminPython + NomPython, "-i -c " + Chr(34) + "print('Hello world!');input('kcc');" + Chr(34), CheminPython,#PB_Program_Open|#PB_Program_Read)
Delay(2000)
While ProgramRunning(p)
If AvailableProgramOutput(p)
o$ + ReadProgramString(p) + #CRLF$
w = ElapsedMilliseconds() + 1000 ; reset timeout
EndIf
e$ = ReadProgramError(p)
If e$
o$ + e$ + #CRLF$
w = ElapsedMilliseconds() + 1000 ; reset timeout
EndIf
If w < ElapsedMilliseconds()
Break
EndIf
Wend
Debug o$
CloseProgram(p)
Code: Select all
; http://www.purebasic.fr/english/viewtopic.php?p=322220#p322220
;process.pb
;Justin 04/10
Structure PROCESS_OBJ
hReadStdOut.i
hWriteStdOut.i
hReadStdErr.i
hWwriteStdErr.i
process.PROCESS_INFORMATION
dataRead.i
lastErrChar.ASCII
lastStdChar.ASCII
EndStructure
#PROCESS_JOIN_OUTPUT = 2 ;stdout and stderr are both redirected to the stdout pipe
Declare.s proc__ReadLine(*lastChar.ASCII, *dataRead, hpipe.i)
;Public functions
Procedure proc_RunProgram(program.s, commad.s, flags.l=0, *err.INTEGER=#Null)
Define.PROCESS_OBJ *this
Define.STARTUPINFO start
Define.SECURITY_ATTRIBUTES sa
Define.i error
*this = AllocateMemory(SizeOf(PROCESS_OBJ))
error = 0
;Create the Pipes
sa\nLength =SizeOf(SECURITY_ATTRIBUTES)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
If CreatePipe_(@*this\hReadStdOut, @*this\hWriteStdOut, @sa, 0)
If CreatePipe_(@*this\hReadStdErr, @*this\hWwriteStdErr, @sa, 0)
start\cb = SizeOf(STARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
start\hStdOutput = *this\hWriteStdOut
If flags & #PROCESS_JOIN_OUTPUT = #PROCESS_JOIN_OUTPUT
start\hStdError = *this\hWriteStdOut
Else
start\hStdError = *this\hWwriteStdErr
EndIf
If CreateProcess_(0, program + " " + commad, @sa, @sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @*this\process)
CloseHandle_(*this\hWriteStdOut)
CloseHandle_(*this\hWwriteStdErr)
Else ;CreateProcess error
error = -3
EndIf
Else ;pipe error
error = -2
EndIf
Else ;pipe error
error = -1
EndIf
If *err : *err\i = error : EndIf
If error=0
ProcedureReturn *this
Else ;error
CloseHandle_(*this\hReadStdErr)
CloseHandle_(*this\hReadStdOut)
CloseHandle_(*this\hWriteStdOut)
CloseHandle_(*this\hWwriteStdErr)
FreeMemory(*this)
ProcedureReturn #Null
EndIf
EndProcedure
Procedure proc_CloseProgram(*this.PROCESS_OBJ)
CloseHandle_(*this\process\hProcess)
CloseHandle_(*this\process\hThread)
CloseHandle_(*this\hReadStdErr)
CloseHandle_(*this\hReadStdOut)
FreeMemory(*this)
EndProcedure
Macro proc_ReadStdOutLine(this)
proc__ReadLine(@this\lastStdChar, @this\dataRead, this\hReadStdOut)
EndMacro
Macro proc_ReadStdErrLine(this)
proc__ReadLine(@this\lastErrChar, @this\dataRead, this\hReadStdErr)
EndMacro
Procedure proc_GetExitCode(*this.PROCESS_OBJ)
Define.i exitCode
If GetExitCodeProcess_(*this\process\hProcess, @exitCode)
ProcedureReturn exitCode
EndIf
EndProcedure
Macro proc_TerminateProcess(this, exitcode)
TerminateProcess_(this\process\hProcess, exitcode)
EndMacro
Macro proc_DataRead(this)
this\dataRead
EndMacro
Procedure.s proc__ReadLine(*lastChar.ASCII, *dataRead.INTEGER, hpipe.i)
Define.ASCII achar
Define.s text
text = ""
While ReadFile_(hpipe, @achar, SizeOf(ASCII), *dataRead, 0)
If achar\a = #CR
*lastChar\a = achar\a
Break
ElseIf achar\a = #LF And *lastChar\a = #CR
*lastChar\a = achar\a
Continue
EndIf
text = text + PeekS(@achar, SizeOf(ASCII), #PB_Ascii)
*lastChar\a = achar\a
Wend
ProcedureReturn text
EndProcedure
;test
Define.s program, cmd, line, text
Define.PROCESS_OBJ *proc
Define.i prog, counter
CheminPython.s = "D:\pyzo2015a\"
NomPython.s = "python.exe"
*proc = proc_RunProgram(CheminPython + NomPython, "-i -c " + Chr(34) + "print('Hello world!');input(kcc);" + Chr(34), 0)
If *proc
counter = 1
line = proc_ReadStdErrLine(*proc)
While proc_DataRead(*proc)
If counter=10
proc_TerminateProcess(*proc, 100)
EndIf
Debug line
line = proc_ReadStdErrLine(*proc)
counter + 1
Wend
Debug proc_GetExitCode(*proc)
proc_CloseProgram(*proc)
EndIf

If you have a good way for open PYTHON, read the answer, sending command, and read the answer, etc..
Finaly remote the console
Have a good day