shell not finishing execution

Post

Posted
Rating:
#1 (In Topic #1263)
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
Part of a program I am updating needs to update the system. To do this I am using the shell command. if I go into a terminal and execute this command it works fine..

echo xxx | sudo -S dnf update -y

however if I put that into the shell command ….

Code (gambas)

  1.   Dim C As String = "echo xxx | sudo -S dnf update -y"
  2.  
  3.   Shell C Wait To H
  4.   Message(H)
  5.  
  6.  

it tells me it is checking the repos, the first thing it should show but nothing else happens. The shell is stopped and the update never happens. Why is the shell not remaining for the 20 minutes it should have taken? how do I make it do this?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 Maybe try Desktop.RunAsRoot() instead as it uses pkexec so should authenticate without you using any tricks.


Desktop.RunAsRoot("dnf update -y")
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 I can always count on you for help. Thanks. This means adding a component to already distributed software which I can deal with. However when I run it, it asks the user for password to run. I can't have this happen as the program will have a stored password to provide but it needs to handle the entire update itself without asking the user anything. Basically an admin has issued the command from another place and often nobody is there to put in a password.
Your solution is almost perfect, can we make it not ask for password and just take from the program?
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Okay look at Process.Expect
/comp/gb.util/process/expect - Gambas Documentation

You can preset a password that way , apparently password prompt ends with :

So maybe…

Process.Expect("*:", "xxx")
Shell "sudo dnf upgrade -y" For input output

I can't test as at work but something along those lines.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 gave that a shot but I get unexpected symbol ".expect"    on the process.expect  line. it seems that expect is not a valid object and I found nothing attached to process that is even close. I see where you are going just can't get there.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
Oops sorry it's not Static

So something like this…

Code (gambas)

  1.   Dim aExec as String[]
  2.   Dim hProcess As Process
  3.  
  4.     aExec = ["sudo", "dnf" , "upgrade", "-y"]
  5.     hProcess = Exec aExec For Input Output As "Proc"
  6.     hProcess.Expect("*:", "xxx")
  7.     hProcess.Wait
  8.  
  9.  
  10.  
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
Hang on..

I just noticed your command uses update not upgrade.
Are you wanting it to completely upgrade files?

for apt (and i think dnf) upgrade actually installs the updates
Try this…

Code (gambas)

  1. Shell "echo 'xxx'|sudo -S dnf upgrade -y" Wait
  2.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 actually with dnf it is update and it does updates within the version you have. There is a different command to upgrade.  So in these cases I am updating fedora 39 to the latest fedora 39,  if I did upgrade it would be going from fedora 39 to fedora 40.
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
tried the solution with the coding and the .expect is still not supported. throws error there. I even copied and pasted it. attempted to retype but the .expect is not there.
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’

sadams54 said

tried the solution with the coding and the .expect is still not supported. throws error there. I even copied and pasted it. attempted to retype but the .expect is not there.

Did you add the gb.util component ?

Sorry Process.Expect is an enhancement provided by gb.util that's  why it's under gb.util in the wiki
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
thank you for all the help. I put in the util and now the process has no errors. However it also does not do the job either. I check and verify but the process never seemed to run. or at least no update was done. And I did wait. But the update process would have a job running and there is none.
Online now: No Back to the top

Post

Posted
Rating:
#12
Guru
BruceSteers is in the usergroup ‘Guru’
Okay , things to try…

Use Exec instead of Shell

End the shell command with 2>&1
Shell "the-command 2>&1"

That forces error (StdErr) messages to print to StdOut

Or something like this to check output and errors  (sorry this code is hand written and not tested)

Code (gambas)

  1.  
  2. Public Sub Update()
  3.  
  4. Dim aExec as String[]
  5. Dim hProcess As Process
  6.  
  7.   TextAreaOutput.Text = "Udating...\n"
  8.  
  9.   aExec = ["sudo", "dnf" , "upgrade", "-y"]
  10.   hProcess = Exec aExec For Input Output As "Proc"
  11.   hProcess.Expect("*:", "xxx")
  12.  
  13.   ' hProcess.Wait   ' I do not know if Process.Wait waits for the process to end or just for the next event so i use the loop below..
  14.   While hProcess.State = Process.Running
  15.     Wait 0.1
  16.   Wend
  17.  
  18.   If hProcess And If hProcess.Value Then
  19.     TextAreaOuput.Text &= "Error number " & Process.Value
  20.  
  21.  
  22. Public Sub Proc_Read()
  23.  
  24.  Dim sTxt As String
  25.   sTxt = Read #Last, Lof(Last)
  26.   TextAreaOutput.Insert(sTxt)
  27.  
  28.  
  29. Public Sub Proc_Error(sTxt As String)
  30.  
  31.   TextAreaOutput.Text &= "\nError: " & sTxt
  32.  
  33.  
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
thank you. that did the trick perfectly.
Online now: No Back to the top
1 guest and 0 members have just viewed this.