[Gambas-user] Strange problem with running Shell on Fedora (code works in IDE but not in executable!!)

Tobias Boege taboege at ...626...
Wed Mar 27 18:54:08 CET 2013


On Wed, 27 Mar 2013, Willy Raets wrote:
> On Wed, 2013-03-27 at 17:22 +0100, Tobias Boege wrote:
> > Well, there are some vague assumptions I could make about what's going on
> > but none of them would be based on knowledge.
> > 
> > So I just propose something: leave the "echo" out of your command string.
> > Instead connect sudo's stdin to your Gambas program directly and write the
> > password you obtained as
> > 
> > Print #hProcess1, sPassword
> > 
> > immediately after your "Shell" instruction (note that you must open the
> > process "For Read Write" now). _Perhaps_ it would even give a better feeling
> > to sudo when you use "For Input Output" instead of "Read Write"...
> > 
> > Maybe you should add Process1_Error() just in case there is something that
> > could help you.
> 
> Hi Tobias,
> 
> Thanks for your answer and you are right. 
> I did implement a Catch but that won't feed me back errors in the
> process. So I started by adding a Process1_Error handle and now in IDE
> all still runs producing a small difference in output.
> It now outputs exactly the same as when I copy/paste the sFull output
> printed in console to a terminal window and hit enter (1 extra line
> saying: error:nothing to do
> 
> When run from executable I now get something returned from the process
> error handle.
> 
> Seems not yum but sudo is complaining:
> 'sudo: sorry, you must have a tty to run sudo'
> 
> tty I understand as terminal. So apparently when run from executable
> shell seems to act different somehow. I can't quite wrap my head around
> it.
> 
> I will have a look at your suggestion on sending the password using read
> write or input output.
> Could you explain the 'Instead connect sudo's stdin to your Gambas
> program directly' a bit more maybe?
> 
> Thanks..

OK, this was my assumption *slapping on my back* but I don't know enough
about the IDE to really put it into the picture assertively.

Even with -S, sudo still wants a tty connected to it (according to the
sources I have available, opening /dev/tty must not fail for sudo). I
remember vaguely that the IDE runs Gambas executables in a pseudo tty (pty)
so that over three edges[0] sudo has access to a pty which it recognises as
a valid tty.

However, if you double-click on your executable on your desktop, there is no
tty or pty involved and sudo complains.

I see three solutions to this:
a) run your Gambas executable from a terminal emulator;
b) tick some checkbox in your DE's dialogs to run the Gambas executable in a
   terminal emulator; or
c) use "For Input Output" in your Shell instruction which, according to the
   docs[1], opens a pty to run the command.

Of course, c) removes the issue in your program and I'd prefer using this
option.

And concerning your question about "connect[ing] sudo's stdin to your Gambas
program": it is faster. You don't need to run "echo" to pipe the password to
sudo if you can pipe the password yourself. The code would look like this:

hProcess = Shell "sudo -S yum ..." For Input Output As "Process"
Print #hProcess, sPass
hProcess.Wait()

This way, you write the password sPass and the newline sudo wants into the
standard input of the sudo process - which is, by means of "For Input
Output" connected to a pty - which is the same thing that "echo" did in your
original code snippet but faster, and eventually resulting in working code,
I hope :-)

Regards,
Tobi

[0] It's a german idiom I couldn't find a translation for. Hope the meaning
    is obvious.
[1] http://gambasdoc.org/help/lang/shell?v3




More information about the User mailing list