Page 1 of 1

Problems receiving output from RunProgram and plink.exe.

Posted: Sat Sep 08, 2012 2:39 pm
by Longshot
I am having an issue receiving any output from plink.exe using PureBasic. If I call the program like so:

Process = RunProgram("C:\plink.exe","-l user -pw password ip_address df -h",GetCurrentDirectory(),#PB_Program_Open | #PB_Program_Read)
Debug ReadProgramString(Process)
Debug ReadProgramError(Process)


It never returns the first line in the debug window. If I call it without commands (no -l, -pw, or IP address) it will return the program's help output, and if I put in the -l and -pw commands it will then give me a request for user or password, but as soon as I make the SSH connection to the server I get nothing at all.

I have a workaround where I run it through cmd.exe and output everything to a text file, but that's hacky and I would rather have more control over the program itself.

Anyone have any ideas? :)

Re: Problems receiving output from RunProgram and plink.exe.

Posted: Sat Sep 08, 2012 3:07 pm
by infratec
Hi,

try this:

Code: Select all

Process = RunProgram("C:\plink.exe","-l user -pw password ip_address df -h",GetCurrentDirectory(),#PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
If Process
  While  ProgramRunning(Process)
    If AvailableProgramOutput(Process)
      Debug ReadProgramString(Process)
    EndIf
    Error$ = ReadProgramError(Process)
    If Len(Error$) > 0
      Debug Error$
    EndIf
  Wend
  ProgramExitCode(Compiler)
EndIf
Bernd

Re: Problems receiving output from RunProgram and plink.exe.

Posted: Sat Sep 08, 2012 4:20 pm
by Longshot
That code returned this in the debug window:

"Unable to read from standard input: The handle is invalid."

Re: Problems receiving output from RunProgram and plink.exe.

Posted: Sat Sep 08, 2012 5:48 pm
by infratec
Than try this:

Code: Select all

Process = RunProgram("C:\plink.exe","-l user -pw password ip-address df -h", GetCurrentDirectory(), #PB_Program_Open | #PB_Program_Read | #PB_Program_Error | #PB_Program_Write)
If Process
  While  ProgramRunning(Process)
    If AvailableProgramOutput(Process)
      Debug ReadProgramString(Process)
    EndIf
    Error$ = ReadProgramError(Process)
    If Len(Error$) > 0
      Debug Error$
    EndIf
  Wend
  ProgramExitCode(Process)
EndIf
It works on my PC.

Bernd

Re: Problems receiving output from RunProgram and plink.exe.

Posted: Sat Sep 08, 2012 7:39 pm
by Longshot
That worked perfectly!

Thanks :D