[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 17:22:55 CET 2013


On Wed, 27 Mar 2013, Willy Raets wrote:
> I have this strange problem on Fedora.
> I have this form (part of a bigger project) that is used to install rpm
> packages on Fedora using yum.
> The form has:
> txbPass (TextBox) to enter password
> tarOutput (TextArea) to output stream read from the running yum in shell
> btnInstall (Button) to click to start installing
> variable PathTemp (String) contains full path to rpm install file 
> 
> The code for btnInstall is: 
> 
> Public Sub btnInstall_Click()
> 
>   Dim sPass, sEPass, sCommand, sFull As String
>   btnClose.Enabled = False
>   tarOutput.Clear
>   Me.Refresh
>   Wait 0.15
>   If tbxPass.Text = Null Then
>     Message.Warning("First enter a password")
>     btnClose.Enabled = True
>     tbxPass.SetFocus
>   Else
>     sPass = tbxPass.Text
>     sEPass = "echo \"" & sPass & "\" | "
>     sCommand = "yum install -y " & PathTemp
>     sFull = sEPass & "sudo -S " & sCommand
>     'TODO: Remove print
>     Print sFull
>     tarOutput.Text = "Start install..\n\n"
>     Wait 0.05
>     hProcess1 = Shell sFull For Read As "Process1"
>     hProcess1.Wait
>     hProcess1.Kill
>     Wait 0.05
>     tarOutput.Text &= "\nEnd install.."
>     btnClose.Enabled = True
>     btnInstall.Enabled = False
>     btnClose.SetFocus
>   Endif
>   
>   Catch
>     tarOutput.Text &= Error.Text
>     If hProcess1.State = 1 Then
>       hProcess1.Kill
>     Endif
>     Error.Clear
> 
> End
> 
> Public Sub Process1_Read()
> 
>   Dim sLine As String
>   Read #hProcess1, sLine, Lof(hProcess1)
>   tarOutput.Text &= sLine
>   tarOutput.Refresh
>   Wait 0.02
>   
> End 
> 
> What happens:
> 1. When running from IDE (debug -> run) the installation runs perfectly
> and application installs.
> tarOutput reads:
> Start install..
> 
> <multiple lines of installation progress output by yum>
> 
> End install..
> 
> 
> 2. When running a gambas executable of the application or install a IDE
> made package of the application the installation doesn't run for some
> reason and rpm package doesn't install
> tarOutput reads:
> Start install..
> 
> 
> End install..
> 
> So no output from the Process1_Read event is added, nor is application
> installed. It seems as if shell is never run!!
> 
> Any ideas here?
> 
> [System]
> OperatingSystem=Linux
> Kernel=3.8.4-102.fc17.i686
> Architecture=x86
> Distribution=redhat Fedora release 17 (Beefy Miracle)
> Desktop=LXDE
> Theme=QWindows
> Language=en_US.UTF-8
> Memory=1003M
> 
> [Libraries]
> GStreamer=libgstreamer-0.10.so.0.30.0
> GTK+=libgtk-x11-2.0.so.0.2400.13
> Poppler=libpoppler.so.19.0.0
> Qt4=libQtCore.so.4.8.4
> SDL=libSDL-1.2.so.0.11.3
> 
> Gambas 3.4.0

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.

Regards,
Tobi




More information about the User mailing list