Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How system() works? 1

Status
Not open for further replies.

ToddT

Programmer
Feb 7, 2003
14
US
Does anybody know if the system( ) function will use the same command line arguments as the program that the function is in? Ex.
void main(int argc, char *argv){
...
system( program arg1 arg2 arg3);
}
Am I correct in thinking that arg1, arg2, and arg3 are totally independent of main's arguments. Also, if you mix cases in Unix will that cause the program to fail? Ex. int Int?
Thanks for the help.
 
The arguments to main and the arguments to the "system()" call are completely unrelated.

UNIX is case-sensitive. Whether or not mixing case causes a program to fail depends on the program.
 
re re Hello

then the best to see it is to try this


#include <stdlib.h>

int main(int argc, char **argv)
{
system(&quot;ls -l&quot;);

return 0;
}

there is abolutly no dependances between main's arguments and what you write in the system line.

except if you construct the &quot;ls -l&quot; with the argc argv arguments.

ex. a sort of : system(argv[0]);

but the argv[0] is only use has a char* type, it is a &quot;dependances&quot; with &quot; &quot;, because in fact, system function takes only a char* arguments, where ever it comes from.

Hope it helps

lcout
 
The system command takes a c string (char*), and is thus unrelated to arguments passed, however, you CAN add the commandline arguments and pass them off to another program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top