Command Pass to Terminal

Linux specific forum
Akat
New User
New User
Posts: 4
Joined: Tue Jul 26, 2005 1:36 pm

Command Pass to Terminal

Post by Akat »

hi guys... im newbie here, im sorry if this question has been answered so many times,:-
* i used glade to do the UI as my front end to 'mencoder' before, but i still cant find a way to pass mencoder command to terminal, im almost give up already n now im looking forward to use PB in oredr to do that...
1. is that any way we can achieve the same within PB... i mean send a string command like 'mencoder a.avi -ovc copy -oac copy b.avi' to the terminal n the rest terminal will execute the command
2. is there any sample codes relative to the 1st question?
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

Hi,

if i understand you right... you want to send a command from within a PureBasic Programm? there's nothing easier... use

Code: Select all

RunProgram()
to start your app.... with or without parameters...

Ulf
Akat
New User
New User
Posts: 4
Joined: Tue Jul 26, 2005 1:36 pm

Post by Akat »

yea man... many thanks... its working... im gonna buy PB soon for this... btw, u guys know how to pass the info back from terminal to a text or PB?
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

Hi,

this is depending on the used program.... if the desired output could be placed in a file (may you have to redirect the screen-output to a file) , you can read this file and get all needed information....

Ulf
Akat
New User
New User
Posts: 4
Joined: Tue Jul 26, 2005 1:36 pm

Post by Akat »

thanks walker... ill try tonite..
Alex
User
User
Posts: 41
Joined: Fri Aug 19, 2005 8:14 pm

Post by Alex »

walker wrote:Hi,

if i understand you right... you want to send a command from within a PureBasic Programm? there's nothing easier... use

Code: Select all

RunProgram()
to start your app.... with or without parameters...

Ulf
What if you want to go a step further, and put the output of the command into a PB variable or filename?

Can I do something like:

Code: Select all

A.s = RunProgram(ls -algFs | grep foo.bar)
Thanks,

Alex
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'

-Beryl Markham
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

At the moment, the output has to redirected to a file then read. Here is an untested example, I'm on a Windows PC at the moment... Hope this helps.

Code: Select all

Command$ = "ps"
Parameters$ = "-A |grep bash >temp.txt"

If RunProgram(Command$,Parameters$,".")

  file = OpenFile(#PB_Any,"temp.txt")
  If file
    While Eof(file) = #False
      Output$ = Output$ + ReadString() + Chr(10)
    Wend
    CloseFile(file)
    DeleteFile("temp.txt")
  EndIf
  
  MessageRequester(Command$ + " " + Parameters$, Output$)
  
EndIf
-Beach
Alex
User
User
Posts: 41
Joined: Fri Aug 19, 2005 8:14 pm

Post by Alex »

Thanks, it was very helpful. I played with it a little, and discovered that for some reason, RunProgram() gets the process id. If I write this:

Code: Select all

Program$="ls"
Parameter$= " -algFs &"
a=RunProgram(Program$,Parameter$,".")
Result$=Str(a)
Print(Result$)
I get the following output:

4869total 136
4 drwxr-xr-x 2 users 4096 Aug 19 16:29 ./
8 drwx--x--x 41 users 8192 Aug 19 11:35 ../
4 -rw-r--r-- 1 users 889 Aug 19 11:10 basictext.pb

The 4896 on the top line of the output is the process ID. Weird, huh?

Alex
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'

-Beryl Markham
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

Actually, it is doing exactly what you asked it to. You are echoing out the process ID and then command you ran is echoing the results. :)

[edit]When I try that code, I get the commands output first - then the process ID...[/edit]
-Beach
Alex
User
User
Posts: 41
Joined: Fri Aug 19, 2005 8:14 pm

Post by Alex »

Beach wrote:Actually, it is doing exactly what you asked it to. You are echoing out the process ID and then command you ran is echoing the results. :)

[edit]When I try that code, I get the commands output first - then the process ID...[/edit]
I'm not worried about getting the Process ID first or last. I'm simply curious about why the code picks up the Process ID at all. If PureBasic is not going to collect the actual program output under Linux, (which makes the most sense to me) it would make far more sense to pick up the exit and/or error codes than grab the $PPID variable.

So is it a bug - the programmer is asking Linux for the wrong stream - or is this useful in some way I don't understand?

Alex
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'

-Beryl Markham
Post Reply