Curious effect on RunProgram

Everything else that doesn't fall into one of the other PB categories.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Curious effect on RunProgram

Post by graves »

Hi,
For testing pourposes I've write this program, calling "FTP.EXE":

Code: Select all

  
  nlog = CreateFile(#PB_Any, "TEST.LOG")
  Program.s = "FTP.EXE"
  Parameter.s = " -s:TEST.FTP 194.179.49.2" 
  WriteStringN(nlog, Program+Parameter)
  npgm = RunProgram(Program, Parameter, ".", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
  if isProgram(npgm)
    while ProgramRunning(npgm)
      while AvailableProgramOutput(npgm)
        textline.s = ReadProgramString(npgm)
        if len(textline): WriteStringN(nlog, textline): endif       
      wend
    wend
  else
    WriteStringN(nlog, "NO PGM: "+Program+Parameter)
  endif
  if isProgram(npgm): CloseProgram(npgm): endif
  CloseFile(nlog)
  END
The TEST.FTP file contains this lines (however, the content is not important)

Code: Select all

USER
PASSWD
put XXR1780.RPGLE QGPL/QRPGSRC.GCR1780
quote rcmd CALL PGM(QGPL/COMPILE) PARM('GCR1780' 'RPGLE')
get QGPL/TOPC XXR1780.LST
quit
When I run this program FROM a CMD.EXE window, the log file shows correctly (host 194.179.49.2 is unreachable)

Code: Select all

FTP.EXE -s:TEST.FTP 194.179.49.2
ftp> Desconectado.
ftp> USER
Comando no válido.
ftp> PASSWD
Desconectado.
ftp> put XXR1780.RPGLE QGPL/QRPGSRC.GCR1780
Desconectado.
ftp> quote rcmd CALL PGM(QGPL/COMPILE) PARM('GCR1780' 'RPGLE')
Desconectado.
ftp> get QGPL/TOPC XXR1780.LST
quit
But, and this is the funny thing, if I run this program calling it from another, without CMD.EXE, the order of log lines is completely different:

Code: Select all

FTP.EXE -s:TEST.FTP 194.179.49.2
Desconectado.
Comando no válido.
Desconectado.
Desconectado.
Desconectado.
USER
PASSWD
put XXR1780.RPGLE QGPL/QRPGSRC.GCR1780
quote rcmd CALL PGM(QGPL/COMPILE) PARM('GCR1780' 'RPGLE')
get QGPL/TOPC XXR1780.LST
quit


WHY????
Zach
Addict
Addict
Posts: 1676
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Curious effect on RunProgram

Post by Zach »

Probably the way that the buffer is being handled?

running it from the command line, you are typing every command, one at a time, right?

Then it would make sense that the I/O buffer is completely in synch.

I am supposing that by running the program from another program, it is probably sending those commands one after the other as fast as it can, because you don't have any routine put in place to monitor the feedback from the program, and/or control how/when it responds to the output it is receiving?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Curious effect on RunProgram

Post by Danilo »

graves wrote:But, and this is the funny thing, if I run this program calling it from another, without CMD.EXE, the order of log lines is completely different:

Code: Select all

FTP.EXE -s:TEST.FTP 194.179.49.2
Desconectado.
Comando no válido.
Desconectado.
Desconectado.
Desconectado.
USER
PASSWD
put XXR1780.RPGLE QGPL/QRPGSRC.GCR1780
quote rcmd CALL PGM(QGPL/COMPILE) PARM('GCR1780' 'RPGLE')
get QGPL/TOPC XXR1780.LST
quit


WHY????
Could it be that "Desconectado.", "Comando no válido.", and "Desconectado." are written to stderr?
The other output written to stdout? It's the only explanation I can think of.
Only the PB team knows the internals of AvailableProgramOutput() and ReadProgramString().
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Re: Curious effect on RunProgram

Post by graves »

Hi,
Zach, it could be, but if I invoke FTP.exe from a CMD window, I say to FTP the file containing all commands, did not send one by one.
FTP receives the same command line in both cases, the only difference is the use of responses that makes PB

Danilo, it seems a reasonable explanation, but I use ReadProgramString() to read data from FTP.exe, and Purebasic help says:

Code: Select all

Reads a line from the output (stdout) of the given program.
All lines read by the program are taken from stdout. (I suppose)

Or is it a compiler bug?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Curious effect on RunProgram

Post by Danilo »

Really weird behaviour. It works only correctly when compiling the program in "Console" mode, so the system
opens the default console automatically.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Re: Curious effect on RunProgram

Post by graves »

Hi, Danilo.
YES!!!
Compiling with CONSOLE option, it works correctly.
Many thanks
Post Reply