|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
execlp command
Hi guys,
I am trying to use the execlp command in my C program to run the PS command and send the output into a file specified in the Argument. Following is the command that I am trying to use without any luck. any help would be greatly appreciated. Thanks, Arun PHP Code:
|
|
#2
|
|||
|
|||
|
I don't think all of your code is here. What is this line supposed to be?
Code:
execlp("/bin/ps","ps > "%s",Argument",NULL);
execlp() does not take printf() like arguments. Also, your double quotes are all over the place. Lastly, gets() is one of the most dangerous method calls ever created in the standard C library. If this is just a school project, ok. If this is meant to ever be used by someone besides you then it needs to be removed. |
|
#3
|
|||
|
|||
|
Quote:
You are right, this is for a school project. I am trying to execute the UNIX's PS command in my C program. If I use the following command in my C program the PS command gets executed and the output of the PS command is written on the screen. execlp("/bin/ps","ps",NULL); But I need to change this command so the output of the PS command goes into a file, which is specified in the Argument as shown in the earliear code. I am not sure where to instert the Argument(file name) in this command. Thanks |
|
#4
|
|||
|
|||
|
Take a look at the sprintf() man page. You'll want something on the order of:
Code:
char command[128];
sprintf( command, "ps > %s", argument );
execlp("/bin/sh", command, NULL);
You want to run the shell instead of ps as you want the redirect - that is a shell concept. As a warning this is totally untested... |
|
#5
|
|||
|
|||
|
why not
Quote:
at least: think about color-blind peoble, don't play with colors!!
__________________
working on Solaris[5-9], preferred languages french and C. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > execlp command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|