less: missing filename using execvp()

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am trying to use execvp() to run less however I keep running into the same error saying that:



Missing filename ("less --help" for help)


I'm assuming I am trying to input the file completely wrong. Could anyone give me some guidance? Here is my code line trying to implement it:



// args[0] == "tempFile" which is in my directory
execvp("less", args)









share|improve this question







New contributor




user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    I am trying to use execvp() to run less however I keep running into the same error saying that:



    Missing filename ("less --help" for help)


    I'm assuming I am trying to input the file completely wrong. Could anyone give me some guidance? Here is my code line trying to implement it:



    // args[0] == "tempFile" which is in my directory
    execvp("less", args)









    share|improve this question







    New contributor




    user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to use execvp() to run less however I keep running into the same error saying that:



      Missing filename ("less --help" for help)


      I'm assuming I am trying to input the file completely wrong. Could anyone give me some guidance? Here is my code line trying to implement it:



      // args[0] == "tempFile" which is in my directory
      execvp("less", args)









      share|improve this question







      New contributor




      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am trying to use execvp() to run less however I keep running into the same error saying that:



      Missing filename ("less --help" for help)


      I'm assuming I am trying to input the file completely wrong. Could anyone give me some guidance? Here is my code line trying to implement it:



      // args[0] == "tempFile" which is in my directory
      execvp("less", args)






      shell c less exec






      share|improve this question







      New contributor




      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 11 mins ago









      user7549121

      1




      1




      New contributor




      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user7549121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          Just as when you execute a shell script on the command line script



          sh -c 'script body here' arg0 arg1 arg2


          the arg0 argument gets placed in $0 (this is usually the name of the process). The first command line argument available in $1 is arg1.



          In your case, use args[0] = "less" and args[1] = "tempFile" in your C code. args[3] should be a null pointer.





          share



























            up vote
            0
            down vote













            argv[0] is meant to be the name you give to the command. The command you execute uses that to know how it was invoked. Typically, you'd want to use something like less here:



            argv[0] = "less";
            argv[1] = "filename";
            argv[2] = NULL;
            execvp("less", argv);




            share



























              up vote
              0
              down vote













              Argument 0, taken from argv[0], is conventionally the command name. Typically it's the same string that you pass as the first argument to execvp (that's what shells do).



              Argument 1, from argv[1], is the first “real” argument. So pass a 3-element array containing: char *args = "less", "tempFile", NULL



              Most languages follow the same argument numbering. For example, if you invoke a shell script, it sees what you pass as argv[0] as its $0, what you pass as argv[1] as $1, etc. Perl is a notable exception: in a Perl script, argv[0] is $0, argv[1] is $ARGV[0], argv[2] is $ARGV[1], etc.





              share




















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                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',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                user7549121 is a new contributor. Be nice, and check out our Code of Conduct.









                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477355%2fless-missing-filename-using-execvp%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                1
                down vote













                Just as when you execute a shell script on the command line script



                sh -c 'script body here' arg0 arg1 arg2


                the arg0 argument gets placed in $0 (this is usually the name of the process). The first command line argument available in $1 is arg1.



                In your case, use args[0] = "less" and args[1] = "tempFile" in your C code. args[3] should be a null pointer.





                share
























                  up vote
                  1
                  down vote













                  Just as when you execute a shell script on the command line script



                  sh -c 'script body here' arg0 arg1 arg2


                  the arg0 argument gets placed in $0 (this is usually the name of the process). The first command line argument available in $1 is arg1.



                  In your case, use args[0] = "less" and args[1] = "tempFile" in your C code. args[3] should be a null pointer.





                  share






















                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Just as when you execute a shell script on the command line script



                    sh -c 'script body here' arg0 arg1 arg2


                    the arg0 argument gets placed in $0 (this is usually the name of the process). The first command line argument available in $1 is arg1.



                    In your case, use args[0] = "less" and args[1] = "tempFile" in your C code. args[3] should be a null pointer.





                    share












                    Just as when you execute a shell script on the command line script



                    sh -c 'script body here' arg0 arg1 arg2


                    the arg0 argument gets placed in $0 (this is usually the name of the process). The first command line argument available in $1 is arg1.



                    In your case, use args[0] = "less" and args[1] = "tempFile" in your C code. args[3] should be a null pointer.






                    share











                    share


                    share










                    answered 6 mins ago









                    Kusalananda

                    111k15216341




                    111k15216341






















                        up vote
                        0
                        down vote













                        argv[0] is meant to be the name you give to the command. The command you execute uses that to know how it was invoked. Typically, you'd want to use something like less here:



                        argv[0] = "less";
                        argv[1] = "filename";
                        argv[2] = NULL;
                        execvp("less", argv);




                        share
























                          up vote
                          0
                          down vote













                          argv[0] is meant to be the name you give to the command. The command you execute uses that to know how it was invoked. Typically, you'd want to use something like less here:



                          argv[0] = "less";
                          argv[1] = "filename";
                          argv[2] = NULL;
                          execvp("less", argv);




                          share






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            argv[0] is meant to be the name you give to the command. The command you execute uses that to know how it was invoked. Typically, you'd want to use something like less here:



                            argv[0] = "less";
                            argv[1] = "filename";
                            argv[2] = NULL;
                            execvp("less", argv);




                            share












                            argv[0] is meant to be the name you give to the command. The command you execute uses that to know how it was invoked. Typically, you'd want to use something like less here:



                            argv[0] = "less";
                            argv[1] = "filename";
                            argv[2] = NULL;
                            execvp("less", argv);





                            share











                            share


                            share










                            answered 6 mins ago









                            Stéphane Chazelas

                            289k54536874




                            289k54536874




















                                up vote
                                0
                                down vote













                                Argument 0, taken from argv[0], is conventionally the command name. Typically it's the same string that you pass as the first argument to execvp (that's what shells do).



                                Argument 1, from argv[1], is the first “real” argument. So pass a 3-element array containing: char *args = "less", "tempFile", NULL



                                Most languages follow the same argument numbering. For example, if you invoke a shell script, it sees what you pass as argv[0] as its $0, what you pass as argv[1] as $1, etc. Perl is a notable exception: in a Perl script, argv[0] is $0, argv[1] is $ARGV[0], argv[2] is $ARGV[1], etc.





                                share
























                                  up vote
                                  0
                                  down vote













                                  Argument 0, taken from argv[0], is conventionally the command name. Typically it's the same string that you pass as the first argument to execvp (that's what shells do).



                                  Argument 1, from argv[1], is the first “real” argument. So pass a 3-element array containing: char *args = "less", "tempFile", NULL



                                  Most languages follow the same argument numbering. For example, if you invoke a shell script, it sees what you pass as argv[0] as its $0, what you pass as argv[1] as $1, etc. Perl is a notable exception: in a Perl script, argv[0] is $0, argv[1] is $ARGV[0], argv[2] is $ARGV[1], etc.





                                  share






















                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Argument 0, taken from argv[0], is conventionally the command name. Typically it's the same string that you pass as the first argument to execvp (that's what shells do).



                                    Argument 1, from argv[1], is the first “real” argument. So pass a 3-element array containing: char *args = "less", "tempFile", NULL



                                    Most languages follow the same argument numbering. For example, if you invoke a shell script, it sees what you pass as argv[0] as its $0, what you pass as argv[1] as $1, etc. Perl is a notable exception: in a Perl script, argv[0] is $0, argv[1] is $ARGV[0], argv[2] is $ARGV[1], etc.





                                    share












                                    Argument 0, taken from argv[0], is conventionally the command name. Typically it's the same string that you pass as the first argument to execvp (that's what shells do).



                                    Argument 1, from argv[1], is the first “real” argument. So pass a 3-element array containing: char *args = "less", "tempFile", NULL



                                    Most languages follow the same argument numbering. For example, if you invoke a shell script, it sees what you pass as argv[0] as its $0, what you pass as argv[1] as $1, etc. Perl is a notable exception: in a Perl script, argv[0] is $0, argv[1] is $ARGV[0], argv[2] is $ARGV[1], etc.






                                    share











                                    share


                                    share










                                    answered 4 mins ago









                                    Gilles

                                    516k12210271555




                                    516k12210271555




















                                        user7549121 is a new contributor. Be nice, and check out our Code of Conduct.









                                         

                                        draft saved


                                        draft discarded


















                                        user7549121 is a new contributor. Be nice, and check out our Code of Conduct.












                                        user7549121 is a new contributor. Be nice, and check out our Code of Conduct.











                                        user7549121 is a new contributor. Be nice, and check out our Code of Conduct.













                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477355%2fless-missing-filename-using-execvp%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Popular posts from this blog

                                        How to check contact read email or not when send email to Individual?

                                        Bahrain

                                        Postfix configuration issue with fips on centos 7; mailgun relay