system() function string length limit The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow can I get a file's size in C?How do function pointers in C work?How does free know how much to free?Improve INSERT-per-second performance of SQLite?What does “#define _GNU_SOURCE” imply?Maximum length of command line argument that can be passed to SQL*Plus?Why are elementwise additions much faster in separate loops than in a combined loop?POSIX limits the number of character acceptable as user input to 4096, how to increase it?Does Posix supply format string macros for printf/scanf?Define length-prefixed const wide string in C

Change bounding box of math glyphs in LuaTeX

How to pronounce 1ターン?

He got a vote 80% that of Emmanuel Macron’s

Arduino Pro Micro - switch off LEDs

First use of “packing” as in carrying a gun

Difference between "generating set" and free product?

Can a novice safely splice in wire to lengthen 5V charging cable?

How are presidential pardons supposed to be used?

What aspect of planet Earth must be changed to prevent the industrial revolution?

How does this infinite series simplify to an integral?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Can undead you have reanimated wait inside a portable hole?

What was the last x86 CPU that did not have the x87 floating-point unit built in?

How to copy the contents of all files with a certain name into a new file?

Am I ethically obligated to go into work on an off day if the reason is sudden?

Can the DM override racial traits?

How does ice melt when immersed in water

Can a 1st-level character have an ability score above 18?

"... to apply for a visa" or "... and applied for a visa"?

Derivation tree not rendering

Why not take a picture of a closer black hole?

Make it rain characters

Windows 10: How to Lock (not sleep) laptop on lid close?



system() function string length limit



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow can I get a file's size in C?How do function pointers in C work?How does free know how much to free?Improve INSERT-per-second performance of SQLite?What does “#define _GNU_SOURCE” imply?Maximum length of command line argument that can be passed to SQL*Plus?Why are elementwise additions much faster in separate loops than in a combined loop?POSIX limits the number of character acceptable as user input to 4096, how to increase it?Does Posix supply format string macros for printf/scanf?Define length-prefixed const wide string in C



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








8















How long can be a string passed to system()?



I know the POSIX minimum is 4096, but I would like to know the actual size I can use. Is there any macro defined in any header for that, similar to FILENAME_MAX?



char cmd[SOME_MACRO];

...
system(cmd);









share|improve this question



















  • 3





    Start worrying if your string is more than 100 KiB. Until then, you should be OK.

    – Jonathan Leffler
    9 hours ago











  • @JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

    – chqrlie
    9 hours ago











  • @JL2210: same thing, cannot really use that for allocation

    – chqrlie
    9 hours ago











  • OK. But the maximum length defined in the C library is size_t (see return value of strlen).

    – JL2210
    9 hours ago












  • If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

    – Zan Lynx
    1 hour ago

















8















How long can be a string passed to system()?



I know the POSIX minimum is 4096, but I would like to know the actual size I can use. Is there any macro defined in any header for that, similar to FILENAME_MAX?



char cmd[SOME_MACRO];

...
system(cmd);









share|improve this question



















  • 3





    Start worrying if your string is more than 100 KiB. Until then, you should be OK.

    – Jonathan Leffler
    9 hours ago











  • @JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

    – chqrlie
    9 hours ago











  • @JL2210: same thing, cannot really use that for allocation

    – chqrlie
    9 hours ago











  • OK. But the maximum length defined in the C library is size_t (see return value of strlen).

    – JL2210
    9 hours ago












  • If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

    – Zan Lynx
    1 hour ago













8












8








8








How long can be a string passed to system()?



I know the POSIX minimum is 4096, but I would like to know the actual size I can use. Is there any macro defined in any header for that, similar to FILENAME_MAX?



char cmd[SOME_MACRO];

...
system(cmd);









share|improve this question
















How long can be a string passed to system()?



I know the POSIX minimum is 4096, but I would like to know the actual size I can use. Is there any macro defined in any header for that, similar to FILENAME_MAX?



char cmd[SOME_MACRO];

...
system(cmd);






c linux posix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Charles Duffy

181k28206261




181k28206261










asked 9 hours ago









Cacahuete FritoCacahuete Frito

656620




656620







  • 3





    Start worrying if your string is more than 100 KiB. Until then, you should be OK.

    – Jonathan Leffler
    9 hours ago











  • @JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

    – chqrlie
    9 hours ago











  • @JL2210: same thing, cannot really use that for allocation

    – chqrlie
    9 hours ago











  • OK. But the maximum length defined in the C library is size_t (see return value of strlen).

    – JL2210
    9 hours ago












  • If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

    – Zan Lynx
    1 hour ago












  • 3





    Start worrying if your string is more than 100 KiB. Until then, you should be OK.

    – Jonathan Leffler
    9 hours ago











  • @JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

    – chqrlie
    9 hours ago











  • @JL2210: same thing, cannot really use that for allocation

    – chqrlie
    9 hours ago











  • OK. But the maximum length defined in the C library is size_t (see return value of strlen).

    – JL2210
    9 hours ago












  • If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

    – Zan Lynx
    1 hour ago







3




3





Start worrying if your string is more than 100 KiB. Until then, you should be OK.

– Jonathan Leffler
9 hours ago





Start worrying if your string is more than 100 KiB. Until then, you should be OK.

– Jonathan Leffler
9 hours ago













@JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

– chqrlie
9 hours ago





@JL2210: cannot use that, SIZE_MAX is not the maximum string length, it is the maximum value for type size_t. This value is usually much larger than anything you can define, especially with automatic storage!

– chqrlie
9 hours ago













@JL2210: same thing, cannot really use that for allocation

– chqrlie
9 hours ago





@JL2210: same thing, cannot really use that for allocation

– chqrlie
9 hours ago













OK. But the maximum length defined in the C library is size_t (see return value of strlen).

– JL2210
9 hours ago






OK. But the maximum length defined in the C library is size_t (see return value of strlen).

– JL2210
9 hours ago














If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

– Zan Lynx
1 hour ago





If this is a problem for your programming, you are better off writing the command arguments into a file and updating the command to read that. Many programs, like the compiler and linker on Windows, can already read arguments from a file. Some Unix programs like xargs can read a stream of arguments and run one copy of the command template for each n arguments.

– Zan Lynx
1 hour ago












3 Answers
3






active

oldest

votes


















8














system exec's a shell with arguments "sh","-c", YourAgumentToSystem, (char*)0 (guaranteed by POSIX), so
the maximum length (not counting the '' terminator) is ARG_MAX -1 -3 -3 - size_of_your_environment.



ARG_MAX is defined in limits.h as




"Maximum length of argument to the exec functions including
environment data."




To measure the size of your environment, you can run:



extern char **environ;
size_t envsz = 0; for(char **e=environ; *e; e++) envsz += strlen(*e)+1;





share|improve this answer




















  • 1





    Note that this value may be large for allocation with automatic storage.

    – chqrlie
    8 hours ago






  • 1





    Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

    – Chris Dodd
    7 hours ago











  • I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

    – Zan Lynx
    1 hour ago


















4














The limit is highly system dependent. It may even depend on the command shell that will be used. You should test the return value of system() to see if the system call was successful: -1 means failure and errno should give you more information. The behavior should be defined for any proper C string.



POSIX documents that system(command) is equivalent to:



execl(<shell path>, "sh", "-c", command, (char *)0);


And also documents ARG_MAX defined in <limits.h> as the limit for the combined lengths of the arguments to exec and the environment variables.



Note however that command may contain wildcards and/or other shell words whose expansion may exceed some other limit. Always check the return value for failure.






share|improve this answer




















  • 1





    @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

    – chqrlie
    9 hours ago






  • 3





    @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

    – chqrlie
    9 hours ago


















3















man 3 system




gives us




DESCRIPTION



The system() library function uses fork(2) to create a child process that executes the shell command specified in command
using execl(3) as follows:



 execl("/bin/sh", "sh", "-c", command, (char *) 0);

system() returns after the command has been completed.


so system() is a wrapper for execl()




From the same page we also see that this call conforms to some standards.




CONFORMING TO



POSIX.1-2001, POSIX.1-2008, C89, C99.




Looking up POSIX.1-2008 produces the following online reference



https://pubs.opengroup.org/onlinepubs/9699919799/



Where we can search for info on the execl function which system takes us to



https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html



Which offers up the following




The number of bytes available for the new process' combined argument and environment lists is ARG_MAX. It is implementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.




And finally ...




ERRORS



The exec functions shall fail if:



[E2BIG] The number of bytes used by the new process image's argument
list and environment list is greater than the system-imposed limit of
ARG_MAX bytes.




So the final check to carry out here is the actual exec implementation rather than relying on the standard just in case the implementation deviated from the standard.



So, man 3 execl reports that the errors returned are the same as documented for execve(2) and man 2 execvw reports the following:




ERRORS



E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large.




Not as precise as the POSIX standard? Best check the code or see the (now) accepted answer :)






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55666911%2fsystem-function-string-length-limit%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    8














    system exec's a shell with arguments "sh","-c", YourAgumentToSystem, (char*)0 (guaranteed by POSIX), so
    the maximum length (not counting the '' terminator) is ARG_MAX -1 -3 -3 - size_of_your_environment.



    ARG_MAX is defined in limits.h as




    "Maximum length of argument to the exec functions including
    environment data."




    To measure the size of your environment, you can run:



    extern char **environ;
    size_t envsz = 0; for(char **e=environ; *e; e++) envsz += strlen(*e)+1;





    share|improve this answer




















    • 1





      Note that this value may be large for allocation with automatic storage.

      – chqrlie
      8 hours ago






    • 1





      Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

      – Chris Dodd
      7 hours ago











    • I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

      – Zan Lynx
      1 hour ago















    8














    system exec's a shell with arguments "sh","-c", YourAgumentToSystem, (char*)0 (guaranteed by POSIX), so
    the maximum length (not counting the '' terminator) is ARG_MAX -1 -3 -3 - size_of_your_environment.



    ARG_MAX is defined in limits.h as




    "Maximum length of argument to the exec functions including
    environment data."




    To measure the size of your environment, you can run:



    extern char **environ;
    size_t envsz = 0; for(char **e=environ; *e; e++) envsz += strlen(*e)+1;





    share|improve this answer




















    • 1





      Note that this value may be large for allocation with automatic storage.

      – chqrlie
      8 hours ago






    • 1





      Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

      – Chris Dodd
      7 hours ago











    • I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

      – Zan Lynx
      1 hour ago













    8












    8








    8







    system exec's a shell with arguments "sh","-c", YourAgumentToSystem, (char*)0 (guaranteed by POSIX), so
    the maximum length (not counting the '' terminator) is ARG_MAX -1 -3 -3 - size_of_your_environment.



    ARG_MAX is defined in limits.h as




    "Maximum length of argument to the exec functions including
    environment data."




    To measure the size of your environment, you can run:



    extern char **environ;
    size_t envsz = 0; for(char **e=environ; *e; e++) envsz += strlen(*e)+1;





    share|improve this answer















    system exec's a shell with arguments "sh","-c", YourAgumentToSystem, (char*)0 (guaranteed by POSIX), so
    the maximum length (not counting the '' terminator) is ARG_MAX -1 -3 -3 - size_of_your_environment.



    ARG_MAX is defined in limits.h as




    "Maximum length of argument to the exec functions including
    environment data."




    To measure the size of your environment, you can run:



    extern char **environ;
    size_t envsz = 0; for(char **e=environ; *e; e++) envsz += strlen(*e)+1;






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 9 hours ago

























    answered 9 hours ago









    PSkocikPSkocik

    35.4k65579




    35.4k65579







    • 1





      Note that this value may be large for allocation with automatic storage.

      – chqrlie
      8 hours ago






    • 1





      Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

      – Chris Dodd
      7 hours ago











    • I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

      – Zan Lynx
      1 hour ago












    • 1





      Note that this value may be large for allocation with automatic storage.

      – chqrlie
      8 hours ago






    • 1





      Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

      – Chris Dodd
      7 hours ago











    • I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

      – Zan Lynx
      1 hour ago







    1




    1





    Note that this value may be large for allocation with automatic storage.

    – chqrlie
    8 hours ago





    Note that this value may be large for allocation with automatic storage.

    – chqrlie
    8 hours ago




    1




    1





    Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

    – Chris Dodd
    7 hours ago





    Its also not guarenteed that exceeding it will fail -- its (just) undefined behavior, so it may work one time you call it and fail the next.

    – Chris Dodd
    7 hours ago













    I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

    – Zan Lynx
    1 hour ago





    I don't think that's the most efficient way to calculate environment size. I believe you can run the pointers up until the NULL and subtract from environ, without involving strlen calls.

    – Zan Lynx
    1 hour ago













    4














    The limit is highly system dependent. It may even depend on the command shell that will be used. You should test the return value of system() to see if the system call was successful: -1 means failure and errno should give you more information. The behavior should be defined for any proper C string.



    POSIX documents that system(command) is equivalent to:



    execl(<shell path>, "sh", "-c", command, (char *)0);


    And also documents ARG_MAX defined in <limits.h> as the limit for the combined lengths of the arguments to exec and the environment variables.



    Note however that command may contain wildcards and/or other shell words whose expansion may exceed some other limit. Always check the return value for failure.






    share|improve this answer




















    • 1





      @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

      – chqrlie
      9 hours ago






    • 3





      @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

      – chqrlie
      9 hours ago















    4














    The limit is highly system dependent. It may even depend on the command shell that will be used. You should test the return value of system() to see if the system call was successful: -1 means failure and errno should give you more information. The behavior should be defined for any proper C string.



    POSIX documents that system(command) is equivalent to:



    execl(<shell path>, "sh", "-c", command, (char *)0);


    And also documents ARG_MAX defined in <limits.h> as the limit for the combined lengths of the arguments to exec and the environment variables.



    Note however that command may contain wildcards and/or other shell words whose expansion may exceed some other limit. Always check the return value for failure.






    share|improve this answer




















    • 1





      @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

      – chqrlie
      9 hours ago






    • 3





      @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

      – chqrlie
      9 hours ago













    4












    4








    4







    The limit is highly system dependent. It may even depend on the command shell that will be used. You should test the return value of system() to see if the system call was successful: -1 means failure and errno should give you more information. The behavior should be defined for any proper C string.



    POSIX documents that system(command) is equivalent to:



    execl(<shell path>, "sh", "-c", command, (char *)0);


    And also documents ARG_MAX defined in <limits.h> as the limit for the combined lengths of the arguments to exec and the environment variables.



    Note however that command may contain wildcards and/or other shell words whose expansion may exceed some other limit. Always check the return value for failure.






    share|improve this answer















    The limit is highly system dependent. It may even depend on the command shell that will be used. You should test the return value of system() to see if the system call was successful: -1 means failure and errno should give you more information. The behavior should be defined for any proper C string.



    POSIX documents that system(command) is equivalent to:



    execl(<shell path>, "sh", "-c", command, (char *)0);


    And also documents ARG_MAX defined in <limits.h> as the limit for the combined lengths of the arguments to exec and the environment variables.



    Note however that command may contain wildcards and/or other shell words whose expansion may exceed some other limit. Always check the return value for failure.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 8 hours ago

























    answered 9 hours ago









    chqrliechqrlie

    63.7k851108




    63.7k851108







    • 1





      @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

      – chqrlie
      9 hours ago






    • 3





      @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

      – chqrlie
      9 hours ago












    • 1





      @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

      – chqrlie
      9 hours ago






    • 3





      @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

      – chqrlie
      9 hours ago







    1




    1





    @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

    – chqrlie
    9 hours ago





    @CacahueteFrito: not that I know. also bear in mind not to allocate too much data with automatic storage. 2MB is already in the risky zone.

    – chqrlie
    9 hours ago




    3




    3





    @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

    – chqrlie
    9 hours ago





    @CacahueteFrito: I was wrong, there is a documented limit: ARG_MAX defined in <limits.h>.

    – chqrlie
    9 hours ago











    3















    man 3 system




    gives us




    DESCRIPTION



    The system() library function uses fork(2) to create a child process that executes the shell command specified in command
    using execl(3) as follows:



     execl("/bin/sh", "sh", "-c", command, (char *) 0);

    system() returns after the command has been completed.


    so system() is a wrapper for execl()




    From the same page we also see that this call conforms to some standards.




    CONFORMING TO



    POSIX.1-2001, POSIX.1-2008, C89, C99.




    Looking up POSIX.1-2008 produces the following online reference



    https://pubs.opengroup.org/onlinepubs/9699919799/



    Where we can search for info on the execl function which system takes us to



    https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html



    Which offers up the following




    The number of bytes available for the new process' combined argument and environment lists is ARG_MAX. It is implementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.




    And finally ...




    ERRORS



    The exec functions shall fail if:



    [E2BIG] The number of bytes used by the new process image's argument
    list and environment list is greater than the system-imposed limit of
    ARG_MAX bytes.




    So the final check to carry out here is the actual exec implementation rather than relying on the standard just in case the implementation deviated from the standard.



    So, man 3 execl reports that the errors returned are the same as documented for execve(2) and man 2 execvw reports the following:




    ERRORS



    E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large.




    Not as precise as the POSIX standard? Best check the code or see the (now) accepted answer :)






    share|improve this answer





























      3















      man 3 system




      gives us




      DESCRIPTION



      The system() library function uses fork(2) to create a child process that executes the shell command specified in command
      using execl(3) as follows:



       execl("/bin/sh", "sh", "-c", command, (char *) 0);

      system() returns after the command has been completed.


      so system() is a wrapper for execl()




      From the same page we also see that this call conforms to some standards.




      CONFORMING TO



      POSIX.1-2001, POSIX.1-2008, C89, C99.




      Looking up POSIX.1-2008 produces the following online reference



      https://pubs.opengroup.org/onlinepubs/9699919799/



      Where we can search for info on the execl function which system takes us to



      https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html



      Which offers up the following




      The number of bytes available for the new process' combined argument and environment lists is ARG_MAX. It is implementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.




      And finally ...




      ERRORS



      The exec functions shall fail if:



      [E2BIG] The number of bytes used by the new process image's argument
      list and environment list is greater than the system-imposed limit of
      ARG_MAX bytes.




      So the final check to carry out here is the actual exec implementation rather than relying on the standard just in case the implementation deviated from the standard.



      So, man 3 execl reports that the errors returned are the same as documented for execve(2) and man 2 execvw reports the following:




      ERRORS



      E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large.




      Not as precise as the POSIX standard? Best check the code or see the (now) accepted answer :)






      share|improve this answer



























        3












        3








        3








        man 3 system




        gives us




        DESCRIPTION



        The system() library function uses fork(2) to create a child process that executes the shell command specified in command
        using execl(3) as follows:



         execl("/bin/sh", "sh", "-c", command, (char *) 0);

        system() returns after the command has been completed.


        so system() is a wrapper for execl()




        From the same page we also see that this call conforms to some standards.




        CONFORMING TO



        POSIX.1-2001, POSIX.1-2008, C89, C99.




        Looking up POSIX.1-2008 produces the following online reference



        https://pubs.opengroup.org/onlinepubs/9699919799/



        Where we can search for info on the execl function which system takes us to



        https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html



        Which offers up the following




        The number of bytes available for the new process' combined argument and environment lists is ARG_MAX. It is implementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.




        And finally ...




        ERRORS



        The exec functions shall fail if:



        [E2BIG] The number of bytes used by the new process image's argument
        list and environment list is greater than the system-imposed limit of
        ARG_MAX bytes.




        So the final check to carry out here is the actual exec implementation rather than relying on the standard just in case the implementation deviated from the standard.



        So, man 3 execl reports that the errors returned are the same as documented for execve(2) and man 2 execvw reports the following:




        ERRORS



        E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large.




        Not as precise as the POSIX standard? Best check the code or see the (now) accepted answer :)






        share|improve this answer
















        man 3 system




        gives us




        DESCRIPTION



        The system() library function uses fork(2) to create a child process that executes the shell command specified in command
        using execl(3) as follows:



         execl("/bin/sh", "sh", "-c", command, (char *) 0);

        system() returns after the command has been completed.


        so system() is a wrapper for execl()




        From the same page we also see that this call conforms to some standards.




        CONFORMING TO



        POSIX.1-2001, POSIX.1-2008, C89, C99.




        Looking up POSIX.1-2008 produces the following online reference



        https://pubs.opengroup.org/onlinepubs/9699919799/



        Where we can search for info on the execl function which system takes us to



        https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html



        Which offers up the following




        The number of bytes available for the new process' combined argument and environment lists is ARG_MAX. It is implementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.




        And finally ...




        ERRORS



        The exec functions shall fail if:



        [E2BIG] The number of bytes used by the new process image's argument
        list and environment list is greater than the system-imposed limit of
        ARG_MAX bytes.




        So the final check to carry out here is the actual exec implementation rather than relying on the standard just in case the implementation deviated from the standard.



        So, man 3 execl reports that the errors returned are the same as documented for execve(2) and man 2 execvw reports the following:




        ERRORS



        E2BIG The total number of bytes in the environment (envp) and argument list (argv) is too large.




        Not as precise as the POSIX standard? Best check the code or see the (now) accepted answer :)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 9 hours ago

























        answered 9 hours ago









        Rob KieltyRob Kielty

        6,43153047




        6,43153047



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55666911%2fsystem-function-string-length-limit%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

            2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

            Mortes em março de 2019 Referências Menu de navegação«Zhores Alferov, Nobel de Física bielorrusso, morre aos 88 anos - Ciência»«Fallece Rafael Torija, o bispo emérito de Ciudad Real»«Peter Hurford dies at 88»«Keith Flint, vocalista do The Prodigy, morre aos 49 anos»«Luke Perry, ator de 'Barrados no baile' e 'Riverdale', morre aos 52 anos»«Former Rangers and Scotland captain Eric Caldow dies, aged 84»«Morreu, aos 61 anos, a antiga lenda do wrestling King Kong Bundy»«Fallece el actor y director teatral Abraham Stavans»«In Memoriam Guillaume Faye»«Sidney Sheinberg, a Force Behind Universal and Spielberg, Is Dead at 84»«Carmine Persico, Colombo Crime Family Boss, Is Dead at 85»«Dirigent Michael Gielen gestorben»«Ciclista tricampeã mundial e prata na Rio 2016 é encontrada morta em casa aos 23 anos»«Pagan Community Notes: Raven Grimassi dies, Indianapolis pop-up event cancelled, Circle Sanctuary announces new podcast, and more!»«Hal Blaine, Wrecking Crew Drummer, Dies at 90»«Morre Coutinho, que editou dupla lendária com Pelé no Santos»«Cantor Demétrius, ídolo da Jovem Guarda, morre em SP»«Ex-presidente do Vasco, Eurico Miranda morre no Rio de Janeiro»«Bronze no Mundial de basquete de 1971, Laís Elena morre aos 76 anos»«Diretor de Corridas da F1, Charlie Whiting morre aos 66 anos às vésperas do GP da Austrália»«Morreu o cardeal Danneels, da Bélgica»«Morreu o cartoonista Augusto Cid»«Morreu a atriz Maria Isabel de Lizandra, de "Vale Tudo" e novelas da Tupi»«WS Merwin, prize-winning poet of nature, dies at 91»«Atriz Márcia Real morre em São Paulo aos 88 anos»«Mauritanie: décès de l'ancien président Mohamed Mahmoud ould Louly»«Morreu Dick Dale, o rei da surf guitar e de "Pulp Fiction"»«Falleció Víctor Genes»«João Carlos Marinho, autor de 'O Gênio do Crime', morre em SP»«Legendary Horror Director and SFX Artist John Carl Buechler Dies at 66»«Morre em Salvador a religiosa Makota Valdina»«مرگ بازیکن‌ سابق نساجی بر اثر سقوط سنگ در مازندران»«Domingos Oliveira morre no Rio»«Morre Airton Ravagniani, ex-São Paulo, Fla, Vasco, Grêmio e Sport - Notícias»«Morre o escritor Flavio Moreira da Costa»«Larry Cohen, Writer-Director of 'It's Alive' and 'Hell Up in Harlem,' Dies at 77»«Scott Walker, experimental singer-songwriter, dead at 76»«Joseph Pilato, Day of the Dead Star and Horror Favorite, Dies at 70»«Sheffield United set to pay tribute to legendary goalkeeper Ted Burgin who has died at 91»«Morre Rafael Henzel, sobrevivente de acidente aéreo da Chapecoense»«Morre Valery Bykovsky, um dos primeiros cosmonautas da União Soviética»«Agnès Varda, cineasta da Nouvelle Vague, morre aos 90 anos»«Agnès Varda, cineasta francesa, morre aos 90 anos»«Tania Mallet, James Bond Actress and Helen Mirren's Cousin, Dies at 77»e