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
38
votes
3 answers

What are shell form and exec form?

What are shell form and exec form of commands? I have gone through several documents to get a clear idea of shell form and exec form. But all looked confusing to me. Can anyone help to figure out what are the difference between these two form? PS:…
Mufeed
  • 3,018
  • 4
  • 20
  • 29
37
votes
2 answers

Setting variables with executing a command with exec

You can set a variable for a single command like this: MY_VARIABLE=my_value ./my_script.sh You can hand off to another script like this: exec ./my_script.sh But when I try to do both like this: exec MY_VARIABLE=my_value ./my_script.sh I get an…
Ken
  • 619
  • 1
  • 7
  • 11
36
votes
4 answers

How to use a variable to indicate a file descriptor in bash?

I want to use a bash variable to indicate a file descriptor, like this: id=6 file=a exec $id<>$file But the usage is wrong: -bash: exec: 6: not found So, how to use a variable to indicate a file descriptor in exec command?
WH's HeV
  • 445
  • 1
  • 5
  • 9
36
votes
1 answer

Is it possible to signal handler to survive after "exec"?

I wrote a signal handler for a process, and fork() after that, the signal handler will be applied to both parent and child processes. If I replace the child process with "exec", the signal handler is no more. I know this happens because "exec" call…
aditya
  • 952
  • 3
  • 16
  • 33
35
votes
4 answers

Is it possible to execute a string in MySQL?

I have to convert a MSSQL stored proc that passes a varchar that is a query: INSERT INTO Results EXEC (@Expresion); This isn't working. I'm pretty sure that EXEC and EXECUTE aren't MySQL commands, but CALL doesn't work either. Does anyone know…
aarona
  • 35,986
  • 41
  • 138
  • 186
35
votes
9 answers

PHP exec() will not execute shell command when executed via browser

I have a certain PHP script that calls exec() to execute a command to convert a PDF to JPG. This command works fine in bash. To preempt your initial troubleshooting guesses, note the following: safe_mode = Off Permission on the directory…
Alex
  • 387
  • 1
  • 4
  • 10
35
votes
5 answers

Faster forking of large processes on Linux?

What's the fastest, best way on modern Linux of achieving the same effect as a fork-execve combo from a large process ? My problem is that the process forking is ~500MByte big, and a simple benchmarking test achieves only about 50 forks/s from the…
timday
  • 24,582
  • 12
  • 83
  • 135
35
votes
3 answers

Why doesn't an import in an exec in a function work?

I can put an import statement in a string, exec it, and it works (prints a random digit): code = """ import random def f(): print random.randint(0,9) """ def f(): pass exec code f() Now, if I put exec code and f() in their own function…
Alex Varga
  • 1,752
  • 2
  • 14
  • 17
35
votes
2 answers

Compile PyPy to Exe

I know how to compile CPython file to exe using cx_freeze but is it possible to compile a simple program using PyPy to Exe ?
Nuncjo
  • 1,290
  • 3
  • 15
  • 16
34
votes
9 answers

Checking if process still running?

As a way to build a poor-man's watchdog and make sure an application is restarted in case it crashes (until I figure out why), I need to write a PHP CLI script that will be run by cron every 5mn to check whether the process is still running. Based…
Gulbahar
  • 5,343
  • 20
  • 70
  • 93
34
votes
2 answers

How to use pipe within -exec in find

Is there any way to use pipe within an -exec in find? I don't want grep to go through whole file, but only through first line of each file. find /path/to/dir -type f -print -exec grep yourstring {} \; I tried to put the pipelines there with "cat"…
beranpa8
  • 435
  • 1
  • 5
  • 11
34
votes
3 answers

Using nodejs's spawn causes "unknown option -- " and "[Error: spawn ENOENT]" errors

I'm trying to get spawn to effect an rm -rf node_modules followed by npm install (on windows 7; nx commands courtesy of a transparently installed CygWin. All nx commands resolve on a commandline just fine). I initially had this using exec, but…
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
33
votes
4 answers

Grabbing output from exec

I'm trying to write a C program that grabs command output and then i'll be passing that to another program. I'm having an issue, I cant work out how to get the command output and store it. Below is a sample of what I have if(fork() == 0){ …
TrewTzu
  • 1,110
  • 2
  • 11
  • 27
32
votes
6 answers

How to pass arguments to the __code__ of a function?

The following works: def spam(): print "spam" exec(spam.__code__) spam But what if spam takes arguments? def spam(eggs): print "spam and", eggs exec(spam.__code__) TypeError: spam() takes exactly 1 argument (0 given) Given, that I…
Turion
  • 5,684
  • 4
  • 26
  • 42
32
votes
1 answer

how to correctly use fork, exec, wait

The shell i'm writing needs to execute a program given to it by the user. Here's the very shortened simplified version of my program int main() { pid_t pid = getpid(); // this is the parents pid char *user_input = NULL; size_t line_sz =…
Collin
  • 1,777
  • 4
  • 26
  • 42