Hello all !
Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C.
Is it OS dependent? If yes, what are the limits for each?
Thanks.
Hello all !
Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C.
Is it OS dependent? If yes, what are the limits for each?
Thanks.
The answer in bytes comes from:
getconf ARG_MAX
it is system dependent
Edit:
Note that ARG_MAX also counts the number of bytes used in environmental variables. So it is argument bytes + env bytes
If the maximum size is even a concern, then you're passing too many arguments. On my system it is 64K but could be far less in other places. Could this data be passed through a pipe instead, or be split across multiple system() calls?
Corona's point is well taken. One point to add:
getconf _POSIX_ARG_MAX
4096
So if POSIX mode is taken as a maximum to be usable "everywhere" then we do not have to worry about excessive arguments. See your limits.h file, or sysconf() man page.
A good solution might be to write a script on the fly, then call system(), popen() or even fork()/exec() to run your text - commands string. The point being that a "universal" accepted lowest limit is pretty small, especially if you factor in ENV variables.
if your application is command prompt based, you can always write a script and call that script in system function..
here is an example which may help.. i used it for an application called gnuplot..
system("gnuplot.exe script_name");
script_name is the script that contains all the commands, in my case all the commands used for plotting..