[Gambas-user] Standard Input & Exec

Tobias Boege taboege at ...626...
Thu Feb 26 11:56:03 CET 2015


On Thu, 26 Feb 2015, John Rose wrote:
> 
> -------- Forwarded Message --------
> Subject: 	Re: [Gambas-user] Standard Input & Exec
> Date: 	Thu, 26 Feb 2015 00:43:46 +0100
> From: 	Tobias Boege <taboege at ...626...>
> Reply-To: 	mailing list for gambas users
> <gambas-user at lists.sourceforge.net>
> To: 	mailing list for gambas users <gambas-user at lists.sourceforge.net>
> 
> I asked Tobi by direct email about my problem. He gave me the solution
> in his reply (shown below) and I coded it as:
> 
> > On Wed, 25 Feb 2015, John Rose wrote:
> >> I want an Exec command to take input from Standard Input. I've looked at
> >> the Gambas documentation and it states:
> >> "If WRITE is specified, data can be sent to the command standard input
> >> by using the Process object with common output instructions: PRINT,
> >> WRITE, ... Note that a reference to the Process object is required.".
> >> 
> >> I don't understand the above. It seems to imply that I should code
> >> penigma_app.Print sPlain (with Dim sPlain As String and sPlain =
> >> "QWERTYU")  where my Exec statement is:
> >> penigma_app = Exec aExecParameters Wait For Read Write As
> >> "EnigmaResultsDetail"
> >> and I have "Dim penigma_app as Process". However, the IDE does not show
> >> Print after coding penigma_app. and the compiler objects.
> >> 
> >
> > The documentation correctly says PRINT, WRITE, ... *instructions*. These are
> > keywords of the Gambas language, not methods of a class:
> > 
> >   Dim hProc As Process
> > 
> >   hProc = Exec ["prog", "arg"] For Read Write
> >   Print #hProc, "input"
> > 
> >> What do I need to do. Also, the Gambas documentation states:
> >> "If you plan to control an application by sending commands to standard
> >> input then testing should be performed outside of the IDE (i.e. make an
> >> executable and launch it from the command line) as the console within
> >> the development environment is not a true virtual terminal and will
> >> cause unexpected results.".
> >> So presumably, I would need to test the app after creating an
> >> executable. So if the executable was named EnigmaWehrmacht.gambas what
> >> would I need to enter on the command line to test this app?
> >> 
> >
> > If your project directory is at /path/to/project, you do:
> > 
> >  $ cd /path/to/project
> >  $ gbc3 -ga  # Re-compile the project
> >  $ gbx3      # Execute the compiled files
> > 
> > This way does not require an executable .gambas archive. But you can also
> > try it with such an archive[*]:
> > 
> >  $ cd /path/to/project
> >  $ gba3                 # Create project.gambas
> >  $ gbr3 project.gambas  # Run it
> > 
> > [*] And sometimes you want to test your project with an executable archive,
> >     too, because certain ways of accessing project data files or something
> >     may work when you run the project under the IDE and via the first way,
> >     but not if you run from an executable archive. But this is entirely
> >     different story.
> 
> aExecParameters = ["/opt/Enigma/enigma_app", 3, sReflector, sLeftRotor,
> sMiddleRotor, sRightRotor, sSteckers, sRings, sGrund]
> penigma_app = Exec aExecParameters For Read Write As "EnigmaResultsDetail"
> Print #penigma_app, sPlain
> Do
>   Wait 0.1
> Loop Until penigma_app.State <> Process.Running
> 
> Thus, I had to remove the Wait keyword in the Exec command and simulate
> it manually.
> 
> Interestingly, even though the Gambas documentation stated that I would
> have to run the app outside the IDE (i.e. by launching the executable
> from the CLI), it still worked OK when I used the Debug command within
> the IDE.
> 

[ Please do not top-post if you want to do my hands a favour. ]

The Gambas documentation didn't "state that [you] would *have to run* the
app outside the IDE". It said "*testing should* be performed outside the
IDE".

Your project is run from the IDE through a PTY which makes the IDE "kinda
look like a terminal" but it doesn't emulate one. For some time now you can
also opt (in the project options) to make the IDE start an external terminal
emulator for you to run the project in. This way you don't have to go
outside the IDE anymore.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list