Questions tagged [execl]

execl() is a C library function which is used to replace the current process image with a new process image. It belongs to the family of exec() functions and prototyped in unistd.h.

execl() is a C library function which is used to replace the current process image with a new process image. It belongs to the familt of exec() functions and prototyped in unistd.h.

The Function Prototype

int execl(const char *path, const char *arg, ...);

where,

  • The first argument is the name of a file that is to be executed.
  • The const char *arg and subsequent arguments (if any) can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program.

Return Value

The various exec() functions only return if an error has occurred. The return value is -1, and errno is set to indicate the error.

Check the Main page for more details.

120 questions
2
votes
2 answers

Redirect the result of execl function

Program: #include #include #include int main() { int cpid=fork(); if(cpid==0){ execl("/bin/ls","ls","-lah","--color",NULL); } else{ int status; …
mohangraj
  • 9,842
  • 19
  • 59
  • 94
1
vote
1 answer

How do I provide input to a background program created by execl?

I am writing a C program on Linux. At the same time I have an executable file A. I need to call A in the C program I am writing. but to run A I need to press any key, and I need to pass a key to the program I am writing after it calls A. The…
1
vote
1 answer

Forcing gzip to overwrite a .gz file in C

I am having a bit of trouble using gzip to compress a file from a C program. I am using this line of code execl("/usr/bin/gzip", "-f", filePath, NULL); to compress the file given by filePath. It works fine the first time (i.e. when there is no…
TommoM
  • 23
  • 4
1
vote
1 answer

Is it possible to stay inside shell opened by a process using execl, right before the process called _exit?

While learning ROP and the uses of gadgets, I've stumbled upon a case where I have a solid one-gadget that executes execl("sh", "-c", "/bin/sh") but does _exit(0x7f) right afterwards. When testing this gadget I'v found that the shell indeed opens,…
Lior Levin
  • 179
  • 1
  • 13
1
vote
1 answer

How should my execl command look in order for it to display "CPU info" in linux command window

I am writing code in C in a Linux terminal trying to display CPU info when the command is run. execl ( "/bin/lscpu","lscpu",(char*)0); I have tried everything and can't seem to find the answer that works. This command is giving me a blank and not…
this.mehhh
  • 11
  • 4
1
vote
1 answer

Why does this program prints an empty line?

This program is called program.c. When I run ./program echo test, I would expect the program to print test, even if the command is run in a subshell. Why is the output an empty line? Does it have to do with filepath? When I try ./program /bin/echo…
JavaDumbell
  • 215
  • 2
  • 11
1
vote
1 answer

replacing system() with execl() : when do I need to use fork()?

I am trying to call an external program from within my C program. I understand that calling system() is a bad habit. I've been reading up on how to use execl() or execv() to replace system(), but due to my limited brain capacity, I would like to…
kwantum
  • 59
  • 6
1
vote
0 answers

problems with redirecting stdout with execl

I originally wrote a little tiny c# server that ran commands on my Linux. The app captured stdout of the command just fine and send them back to the client. Then my c# environment on the Linux box became problematic. So I decided to rewrite…
moonless
  • 23
  • 5
1
vote
2 answers

How can I run system commands in C/C++ using `execl()`, passing the function arguments only as a command line, not as an executable file?

I would like to execute this command in a C/C++ program: stat -c "%F %A %n" *filename goes here* The filename is stored in the main function's argv[1]. I tried it as execl("/bin/stat", "stat", "-c", "\"%F %A %n\"", "file", NULL); How should the…
1
vote
1 answer

Cannot access Docker --build-arg from RUN command (exec form)

I'm trying to use a --build-arg in one of my run statements, but it is failing. Dockerfile ARG OS_VERSION ... RUN ["node", "./bin/installtoolchain.js", "${OS_VERSION}"] I build the image using the following command: docker build --tag installer…
Zak
  • 12,213
  • 21
  • 59
  • 105
1
vote
1 answer

Why my code works without chroot function, but fail with chroot function?

I try to make my code work under chroot('/root/test1'), but it doesn't work correctly. But when I delete chroot('/root/test1'), and modify execl("/test2", "test2", NULL) to execl("/root/test1/test2", "test2", NULL), it will work very well as…
Steve
  • 21
  • 5
1
vote
1 answer

execl() using an integer in arguments (ping)

I've been attempting to create two children to one parent process using fork(), then running two 'different' commands for those two children. I'm attempting to ping two different websites with these child processes. The thing is when the first ping…
aaromated
  • 23
  • 7
1
vote
2 answers

Execlp vs Execl

Is there any occasion in which is better to use execl instead of execlp? I think that maybe when a program is in two different folders using execlp could lead to confusion but I don't know if it is the only case. I ask because one could think that…
S.Alfaro
  • 17
  • 2
  • 8
1
vote
0 answers

getting output from excl used to run a shell script

Hi i would like to get suggestions as to getting output from a script which i am supposed to execute from an excl call: void getCurrentFSLSMode(char* const in_fsls_directory, enum Mode* out_mode) { int link[2]; pid_t pid; char…
user3414321
  • 421
  • 1
  • 4
  • 11
1
vote
0 answers

Not able to report successful copied status and time complexity is bad?

My code is to copy any file from one folder to another. Below is my approach but i am not sure whether this is the best approach?There are two problem with my code : int copycommand(char *source, char *destination) { int childExitStatus; …