Jump to content

How do i do this?


Recommended Posts

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]

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...