It is currently Wed Oct 21, 2020 2:51 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Sending commands to external terminal (Linux)
PostPosted: Fri Sep 25, 2020 8:28 am 
Offline
New User
New User

Joined: Thu Dec 26, 2019 3:31 pm
Posts: 6
I am trying to automate certain tasks from PB, using the native OS terminal, but without success.
As an example:
Code:
rp = RunProgram("xterm", "", "", #PB_Program_Open | #PB_Program_Write)
WriteProgramStringN(rp,"df -h")
CloseProgram(rp)
I expected this to open the terminal, then write the command 'df -h' to it. The terminal opens, but the string is not passed.
I have also tried passing the command as a parameter,i.e.
Code:
rp = RunProgram("xterm", "df -h", "", #PB_Program_Open | #PB_Program_Write)
, but this time the terminal does not even open.
Any help would be much appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Sending commands to external terminal (Linux)
PostPosted: Fri Sep 25, 2020 9:22 am 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 940
Hi,

xterm is a GUI program (a terminal), not a shell (command line tool), you can't send command to it with WriteProgramStringN. An equivalent to sendmessage should be used.

df (Disk Free) is not a command shell, it's a command line software (a binary like an exe in Windows). You can't use it as parameter.
Code:
$ file df
df: ELF 64-bit LSB executable, ...
Use it directly or in a shell

If you want to do something, do like example in help
Code:
Compiler = RunProgram("df", "-h", "", #PB_Program_Open | #PB_Program_Read)
Output$ = ""
If Compiler
  While ProgramRunning(Compiler)
    If AvailableProgramOutput(Compiler)
      Output$ + ReadProgramString(Compiler) + Chr(13)
    EndIf
  Wend
  Output$ + Chr(13) + Chr(13)
  Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
 
  CloseProgram(Compiler)
EndIf

MessageRequester("Output", Output$)

:wink:

_________________
(English is not my native language, I use an online translator.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Sending commands to external terminal (Linux)
PostPosted: Fri Sep 25, 2020 4:20 pm 
Offline
New User
New User

Joined: Thu Dec 26, 2019 3:31 pm
Posts: 6
Thanks Marc56us for the very fullsome reply.
What I am actually trying to accomplish is significantly more in depth than calculating disk space.(It just seemed like a nice trivial example to be getting on with.)
At least now know why it wasn't working.
I think I shall resort to writing out a shell script, then run that using RunProgram().
Many thanks.
Kian


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye