Page 1 of 1

Curious effect on RunProgram

Posted: Tue Apr 02, 2013 10:32 am
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????

Re: Curious effect on RunProgram

Posted: Sat Apr 06, 2013 1:29 pm
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?

Re: Curious effect on RunProgram

Posted: Sat Apr 06, 2013 6:45 pm
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().

Re: Curious effect on RunProgram

Posted: Sun Apr 07, 2013 8:15 am
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?

Re: Curious effect on RunProgram

Posted: Sun Apr 07, 2013 5:45 pm
by Danilo
Really weird behaviour. It works only correctly when compiling the program in "Console" mode, so the system
opens the default console automatically.

Re: Curious effect on RunProgram

Posted: Mon Apr 08, 2013 8:29 am
by graves
Hi, Danilo.
YES!!!
Compiling with CONSOLE option, it works correctly.
Many thanks