Command Pass to Terminal
Command Pass to Terminal
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?
* 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?
Hi,
if i understand you right... you want to send a command from within a PureBasic Programm? there's nothing easier... use to start your app.... with or without parameters...
Ulf
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()Ulf
What if you want to go a step further, and put the output of the command into a PB variable or filename?walker wrote:Hi,
if i understand you right... you want to send a command from within a PureBasic Programm? there's nothing easier... useto start your app.... with or without parameters...Code: Select all
RunProgram()
Ulf
Can I do something like:
Code: Select all
A.s = RunProgram(ls -algFs | grep foo.bar)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
-Beryl Markham
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
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:
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
Code: Select all
Program$="ls"
Parameter$= " -algFs &"
a=RunProgram(Program$,Parameter$,".")
Result$=Str(a)
Print(Result$)
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
-Beryl Markham
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.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]
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
-Beryl Markham



