less: missing filename using execvp()
Clash 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)
shell c less exec
New contributor
add a comment |Â
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)
shell c less exec
New contributor
add a comment |Â
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)
shell c less exec
New contributor
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
shell c less exec
New contributor
New contributor
New contributor
asked 11 mins ago
user7549121
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
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.
add a comment |Â
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);
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered 6 mins ago
Kusalananda
111k15216341
111k15216341
add a comment |Â
add a comment |Â
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);
add a comment |Â
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);
add a comment |Â
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);
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);
answered 6 mins ago
Stéphane Chazelas
289k54536874
289k54536874
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered 4 mins ago
Gilles
516k12210271555
516k12210271555
add a comment |Â
add a comment |Â
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.
user7549121 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password