iphitus Posted July 22, 2003 Report Share Posted July 22, 2003 I've found a python implementation of this. http://python.org/doc/current/lib/module-commands.html But i'm looking for a way to do this in kylix(c++). I want to run a command line command. Eg "mpg123 /home/james/music/abc123.mp3" I can do this in python with: import commands commands.getoutput('/usr/bin/mpg123 /home/james/music/abc123.mp3') Any ideas? James[/code] Quote Link to comment Share on other sites More sharing options...
tyme Posted July 22, 2003 Report Share Posted July 22, 2003 i seem to remember a function called system ......it's been 2 years since I've done any C++ so...my memory could be wrong. Quote Link to comment Share on other sites More sharing options...
johnnyv Posted July 22, 2003 Report Share Posted July 22, 2003 system() sounds about right. type "man system" in a terminal or man:/system in kounquer also have a look at "exec" and "fork" enjoy. Quote Link to comment Share on other sites More sharing options...
iphitus Posted July 26, 2003 Author Report Share Posted July 26, 2003 Nup didn't work, though johnnyv thanks for the bash ways. i tried system("/usr/bin/xmms"); This didn't work either. system("xmms"); They compiled, but it didn't work. XMMS didn't run. Yes that's where XMMS is located. What do i do? Quote Link to comment Share on other sites More sharing options...
Glitz Posted July 26, 2003 Report Share Posted July 26, 2003 If Kylix is anything like BC5 then you should try consulting the help system. It should tell you how to use the system() function as well as show you all related functions. Glitz. Quote Link to comment Share on other sites More sharing options...
johnnyv Posted July 27, 2003 Report Share Posted July 27, 2003 Nup didn't work, though johnnyv thanks for the bash ways. i tried system("/usr/bin/xmms"); This didn't work either. system("xmms"); They compiled, but it didn't work. XMMS didn't run. Yes that's where XMMS is located. What do i do? Strange i just did this: #include <stdlib.h> #include <iostream.h> int main() { if(system("et")) { cout<<"Program executed"<<endl; } else { cout<<"Program failed to execute"<<endl; } return 0; } g++ system_test.cpp -o test on running ./test Enemyterritory started up fine so i quite et and it printed "Program failed to execute" :roll: Obviously i don't know what im doing, but system does open programs. Quote Link to comment Share on other sites More sharing options...
johnnyv Posted July 27, 2003 Report Share Posted July 27, 2003 Ok it looks like it returns 0 on success and something else on failure #include <stdlib.h> #include <iostream.h> int value; int main() { value = system("et"); cout<<"system returned "<<value<<endl; return 0; } changing "et" to "frog" gives [john@bob c++]$ ./test sh: line 1: frog: command not found system returned 32512 [john@bob c++]$ so it looks like system works as advertised. Quote Link to comment Share on other sites More sharing options...
static Posted July 28, 2003 Report Share Posted July 28, 2003 Wouldn't it need to return a 0 to print out Program Exec Failed in your 2nd to last post? Quote Link to comment Share on other sites More sharing options...
tyme Posted July 28, 2003 Report Share Posted July 28, 2003 Wouldn't it need to return a 0 to print out Program Exec Failed in your 2nd to last post? yes, the program (et) would have to return a 1 to get the "program executed" message, or a 0 for "program failed to execute". I don't think et would be returning either a 1 or a 0 ;-) because it's not expecting to have to give a boolean response to any program. in essence, the if/else statement he has just doesn't work... Quote Link to comment Share on other sites More sharing options...
johnnyv Posted July 28, 2003 Report Share Posted July 28, 2003 Wouldn't it need to return a 0 to print out Program Exec Failed in your 2nd to last post? yes, the program (et) would have to return a 1 to get the "program executed" message, or a 0 for "program failed to execute". I don't think et would be returning either a 1 or a 0 ;-) because it's not expecting to have to give a boolean response to any program. in essence, the if/else statement he has just doesn't work... I realised that. I didn't read the system() function def untill after i was expecting it to give a 1 on success which was not the case. I also did not expect et to return anything i expected the function that called et to return a value as most functions do. system(NULL); returns 1 system(""); returns 0 so it seems to give 0 on success unless you put "" as the argument which also gives 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.