Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 11, 2003 Q: execute system command and grab output? | ||||
---|---|---|---|---|
| ||||
How can we execute a system command from D and grab the output ? I guess executing it on a separate thread should be trivial, (if not can you throw that in also? :) (I've seen: extern(C) int system(char*); int main() { system("some_program"); return 0; } // system is <stdlib.h> // exec.. is <unistd.h> is it preferred on unix? ) Thanks Ant |
October 11, 2003 Re: execute system command and grab output? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | You can use popen and the like to implement a cross-platform solution . Id like a copy when your done ;). C "Ant" <Ant_member@pathlink.com> wrote in message news:bm7ts9$2i75$1@digitaldaemon.com... > How can we execute a system command from D > and grab the output ? > > I guess executing it on a separate thread should be trivial, > (if not can you throw that in also? :) > > (I've seen: > > extern(C) int system(char*); > int main() > { > system("some_program"); > return 0; > } > > // system is <stdlib.h> > // exec.. is <unistd.h> is it preferred on unix? > ) > > Thanks > > Ant > > |
October 11, 2003 Re: execute system command and grab output? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | In article <bm9k5k$1qc8$1@digitaldaemon.com>, Charles Sanders says... > >You can use popen and the like to implement a cross-platform solution . Id like a copy when your done ;). > >C man popen "The popen() function opens a process by creating a pipe, forking, and invoking the shell." Thanks Ant |
October 13, 2003 Re: execute system command and grab output? - POpen.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders Attachments: | In article <bm9k5k$1qc8$1@digitaldaemon.com>, Charles Sanders says... > >You can use popen and the like to implement a cross-platform solution . Id like a copy when your done ;). > >C see attachment. How do you like it? Please send back improvements or suggestions. For now this is good enought for me as I can run 'make' from leds and capture the output into a text widget :) (maybe it's just another "pointless wrappers around C runtime library functions or OS API functions" but i prefer to do it like this.) It's not ideal as we might want stderr also. (in linux/bash append " 2>&1" to the command to send stderr into stdout) Probably it's possible to grab stdin/out/err of a process that's already started but I've not idea here to look) Ant |
October 13, 2003 Re: execute system command and grab output? - POpen.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | Cool ill check it out when i get home :D. C "Ant" <Ant_member@pathlink.com> wrote in message news:bmf302$2vfc$1@digitaldaemon.com... > In article <bm9k5k$1qc8$1@digitaldaemon.com>, Charles Sanders says... > > > >You can use popen and the like to implement a cross-platform solution . Id > >like a copy when your done ;). > > > >C > > see attachment. > > How do you like it? Please send back improvements or suggestions. For now this is good enought for me as I can run 'make' from leds and capture the output into a text widget :) > > (maybe it's just another > "pointless wrappers around C runtime library functions or OS API functions" > but i prefer to do it like this.) > > It's not ideal as we might want stderr also. > (in linux/bash append " 2>&1" to the command to send stderr into stdout) > Probably it's possible to grab stdin/out/err of a process that's > already started but I've not idea here to look) > > > Ant > > > |
October 13, 2003 Re: execute system command and grab output? - POpen.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | In article <bmf5tk$22q$1@digitaldaemon.com>, Charles Sanders says... > >Cool ill check it out when i get home :D. > >C opps... probably,after the cycle on read(), we need: // not tested if ( line.length > 0 ) { foreach(POpenLineListener listener; lineListeners) { listener.popenLineCallback(line.dup); } } but I guess this will never get us the last line if it's empty... Ant |
October 15, 2003 Re: execute system command and grab output? - POpen.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | In article <bmf5tk$22q$1@digitaldaemon.com>, Charles Sanders says... >You can use popen and the like to implement a cross-platform solution . So, will it run on Windows just how it is? (I added a notification of "job end" to the interfaces.) Ant |
Copyright © 1999-2021 by the D Language Foundation