Page 1 of 1

Command Pass to Terminal

Posted: Tue Jul 26, 2005 1:51 pm
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?

Posted: Tue Jul 26, 2005 10:40 pm
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

Posted: Mon Aug 01, 2005 8:48 am
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?

Posted: Thu Aug 04, 2005 6:23 am
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

Posted: Thu Aug 04, 2005 11:02 am
by Akat
thanks walker... ill try tonite..

Posted: Fri Aug 19, 2005 8:26 pm
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

Posted: Fri Aug 19, 2005 8:56 pm
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

Posted: Sat Aug 20, 2005 12:48 am
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

Posted: Sat Aug 20, 2005 1:09 am
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]

Posted: Sat Aug 20, 2005 7:03 pm
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