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

Willy Raets willy at ...2734...
Wed Mar 27 19:53:04 CET 2013


On Wed, 2013-03-27 at 18:54 +0100, Tobias Boege wrote:
> 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 :-)
> 
As I all ready implemented READ WRITE it was a small step to INPUT
OUTPUT.

This is how I have it now:

    ....
    sPass = tbxPass.Text
    sCommand = "yum install -y " & PathTemp
    sFull = "sudo -S " & sCommand
    'TODO: Remove print
    Print sFull
    tarOutput.Text = "Start install..\n"
    Wait 0.05
    hProcess1 = Shell sFull For Input Output As "Process1"
    Print #hProcess1, sPass
    hProcess1.Wait
    hProcess1.Kill
    ....

Public Sub Process1_Read()

  Dim sLine As String
  tarOutput.Text &= "\n"
  Line Input #hProcess1, sLine
  tarOutput.Text &= sLine
  tarOutput.Refresh
  Wait 0.02
  
End 

Public Sub Process1_Error(MyError As String)
  
  tarOutput.Text &= MyError & "\n" 
  
End

Again in IDE is runs
In executable it gives same error as before on tty!!



-- 
Kind regards,

Willy (aka gbWilly)

http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org



-------------- next part --------------
A non-text attachment was scrubbed...
Name: FromIDE-InputOutput.png
Type: image/png
Size: 29273 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20130327/32e1c133/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FromExecutable-InputOutput-used.png
Type: image/png
Size: 12379 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20130327/32e1c133/attachment-0001.png>


More information about the User mailing list