Problems receiving output from RunProgram and plink.exe.

Just starting out? Need help? Post your questions and find answers here.
Longshot
User
User
Posts: 12
Joined: Sat Sep 08, 2012 2:32 pm

Problems receiving output from RunProgram and plink.exe.

Post 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? :)
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
Longshot
User
User
Posts: 12
Joined: Sat Sep 08, 2012 2:32 pm

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

Post by Longshot »

That code returned this in the debug window:

"Unable to read from standard input: The handle is invalid."
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
Longshot
User
User
Posts: 12
Joined: Sat Sep 08, 2012 2:32 pm

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

Post by Longshot »

That worked perfectly!

Thanks :D
Post Reply