add command text output to textarea.

Post

Posted
Rating:
#1 (In Topic #1355)
Regular
theyikes is in the usergroup ‘Regular’
Ok first hands up who's fed up with me asking questions? :) Ok all joking aside i'm back with yet another question.

Basically i'm trying to run a shell command and feed the output back to a textarea.

I figured out how to get Gambas to confirm a command with the user password. Here's what I've got so far:

Dim Command As String
  Command = "pkexec ls /root"
  Shell Command Wait For Read As "Answer"

It's a step further than what i had, which was when i hit the Command Button i got no prompt

Apologies again for all the questions but i do have to say that gambas is HIGHLY addictive.
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
theyikes is in the usergroup ‘Regular’
this really has me thinking, I mean i can write the contents of a textarea to a file but for some reason I cannot write the shell output to a file. I know i can do it but i need a little help guys. PLEASE!!
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Try this: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim sResult As String
  4.  
  5.   Shell "ls -a" To sResult  
  6.   TextArea1.Text = sResult
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
theyikes is in the usergroup ‘Regular’
 Cogier you make it all so simple!!! Your little gem of code works a treat. A thousand thank you's! Gambas is fun!!
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
theyikes is in the usergroup ‘Regular’
Dim sResult As String
   
  Shell "ls -a" To sResult  
  TextArea1.Text = sResult

I don't mean to double post but in case someone in the future is having trouble with the same issue then let it be noted as "SOLVED"
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
theyikes is in the usergroup ‘Regular’
sorry cogier. I'm back.
i tried running :
 Dim sResult As String
 Dim command As String
  command = ("lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL") To sResult  
  TextArea1.Text = sResult

but I keep getting an unexpected 2 error. I have no idea on how to handle errors. Can you help me out again!!!
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
theyikes is in the usergroup ‘Regular’
apologies the actual error I'm getting is
unexpected to fmain class 12
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
Yikes, shocker  :o

Where's the Shell command gone?
/lang/shell - Gambas Documentation

your shell command cannot run itself in gambas code you need to use Shell or Exec

Code (gambas)

  1.  
  2. Dim sResult As String
  3. Dim command As String
  4.  
  5. command = "lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL"
  6.  
  7. Shell command To sResult
  8.  
  9. TextArea1.Text = sResult
  10.  
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
theyikes is in the usergroup ‘Regular’
 You're not going to believe this BruceSteers but what you're saying is finally beginning to make sense!! I think what you're teaching me is finally beginning to make sense to me.
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
theyikes is in the usergroup ‘Regular’
 I can read it now and it's beginning to make sense to me. The student is only as good as the teacher!!!
Online now: No Back to the top

Post

Posted
Rating:
#11
Regular
theyikes is in the usergroup ‘Regular’
okay I'm trying this, but i'm not getting any feedback:

Dim sResult As String
 Dim command As String
 command = "sudo fdisk -l"
 Shell command To sResult
 TextArea1.Text = sResult
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
theyikes is in the usergroup ‘Regular’
 I Know it's got something to do with running the command as Sudo.
Online now: No Back to the top

Post

Posted
Rating:
#13
Guru
BruceSteers is in the usergroup ‘Guru’
Yes well sudo will require a terminal to input your password and the Shell command does not have one.

Try pkexec,
pkexec will open the GUI password requester and allow your root command to pass

you MUST run a pkexec command with XAUTHORITY and DISPLAY environment variables like this for 'lsblk -l'..

Code (gambas)

  1. Shell "pkexec env DISPLAY=$DISPLAY XAUTORITY=$XAUTHORITY lsblk -l" Wait To sResult
  2.  
Or this..

Code (gambas)

  1. Shell "pkexec lsblk -l" With ["DISPLAY=$DISPLAY", "XAUTORITY=$XAUTHORITY"] Wait To sResult
  2.  

Or this..

Code (gambas)

  1. Shell "pkexec lsblk -l" With ["DISPLAY=" & Env["DISPLAY"], "XAUTORITY=" 7 Env["XAUTHORITY"]] Wait To sResult
  2.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.