Questions tagged [exec]

This tag refers to the starting of another, subsidiary program. It is named after the family of POSIX system calls whose name starts with “exec” (notably “execve”) though similar concepts exist on other platforms as well, especially when combined with the starting up of another process.

From The Open Group Base Specifications Issue 7

The exec family of functions shall replace the current process image with a new process image. The new image shall be constructed from a regular, executable file called the new process image file. There shall be no return from a successful exec, because the calling process image is overlaid by the new process image.

This tag is commonly used with when it refers to execute an external program within a php code.

Examples

echo exec('whoami');

References

5914 questions
31
votes
5 answers

How to execute command with parameters?

How am I to execute a command in Java with parameters? I've tried Process p = Runtime.getRuntime().exec(new String[]{"php","/var/www/script.php -m 2"}); which doesn't work. String[] options = new String[]{"option1",…
Alex
  • 325
  • 1
  • 4
  • 5
31
votes
1 answer

When should I use O_CLOEXEC when I open file in Linux?

My process forks several times, and each time the child will exec - means I want it to run some other program. In the main process I open a file descriptor with the open() syscall. Would it be correct to give it a flag O_CLOEXEC so the new program…
Bush
  • 2,433
  • 5
  • 34
  • 57
30
votes
2 answers

How to call execl() in C with the proper arguments?

i have vlc (program to reproduce videos) if i type in a shell: /home/vlc "/home/my movies/the movie i want to see.mkv" it opens up an reproduces the movie. however, when I run the following program: #include int main(void) { …
Matias Morant
  • 513
  • 2
  • 5
  • 12
28
votes
2 answers

PHP Untar-gz without exec()?

How would I untar-gz a file in php without the use of exec('tar') or any other commands, using pure PHP? My problem is as follows; I have a 26mb tar.gz file that needs to be uploaded onto my server and extracted. I have tried using net2ftp to…
Jack Wilsdon
  • 6,706
  • 11
  • 44
  • 87
27
votes
5 answers

execute two shell commands in single exec php statement

I want to display all the files that are modified after a specified date the commands are touch --date '2011-09-19 /home/ , find /home/ How i can execute this two commands in single exec statement.Thanks in advance
Warrior
  • 5,168
  • 12
  • 60
  • 87
27
votes
8 answers

Executing a shell command from Common Lisp

How can i execute a shell (bash) command within a Common Lisp program and assign the output to a variable?
Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40
27
votes
2 answers

golang exec background process and get its pid

Situation: I want to run a command that puts itself into the background. If it makes it more possible, then I'll run the command in foreground and bring it into the background by myself. Question: When the process runs in background: how can I get…
sbs
  • 1,139
  • 3
  • 13
  • 19
27
votes
5 answers

What can cause exec to fail? What happens next?

What are the reasons that an exec (execl,execlp, etc.) can fail? If you make a call to exec and it returns, are there any best practices other than just panicking and calling exit?
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
27
votes
2 answers

How can I achieve bash EXIT trap when exec-ing another binary?

I'd like to use a bash EXIT trap and use exec to avoid spawning a new process. Is this possible? That is, #!/bin/bash touch $0.$$ trap "rm -v $0.$$" EXIT /bin/echo Hello removes the temporary file $0.$$ using bash's EXIT trap…
Rhys Ulerich
  • 1,242
  • 1
  • 12
  • 28
27
votes
4 answers

PHP return_var codes?

I'm testing the php exec command: http://php.net/exec and I'm getting back a result code of 127. My php code is: executing 'hello':
"; exec ("hello", $output, $result); var_dump($output); print "
$result"; print "
end…
Jeffrey Berthiaume
  • 4,054
  • 3
  • 35
  • 45
26
votes
6 answers

PHP exec() as Background Process (Windows Wampserver Environment)

I'm trying to setup a php trigger file that will set off a background process. (see this question) I'm doing this on a Windows Wampserver environment. So for example I have trigger.php that runs the exec function that calls for my…
Emmanuel
  • 4,933
  • 5
  • 46
  • 71
26
votes
4 answers

Cannot change global variables in a function through an exec() statement?

Why can I not change global variables from inside a function, using exec()? It works fine when the assignment statement is outside of exec(). Here is an example of my problem: >>> myvar = 'test' >>> def myfunc(): ... global myvar ... …
linkmaster03
  • 4,038
  • 6
  • 25
  • 22
26
votes
6 answers

Using Quotes within getRuntime().exec

I'd like to invoke bash using a string as input. Something like: sh -l -c "./foo" I'd like to do this from Java. Unfortunately, when I try to invoke the command using getRuntime().exec, I get the following error: foo": -c: line 0:…
Daniel
  • 23,365
  • 10
  • 36
  • 34
26
votes
5 answers

How to exit from find -exec if it fails on one of the files

I want to run the command find some/path -exec program \{} \; but I want the find command to quit as soon as the command program \{} fails on any of the files found. Is there a simple way of doing this?
FORTRAN
  • 567
  • 1
  • 6
  • 13
25
votes
6 answers

bash: force exec'd process to have unbuffered stdout

I've got a script like: #!/bin/bash exec /usr/bin/some_binary > /tmp/my.log 2>&1 Problem is that some_binary sends all of its logging to stdout, and buffering makes it so that I only see output in chunks of a few lines. This is annoying when…
bstpierre
  • 30,042
  • 15
  • 70
  • 103