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
58
votes
6 answers

Why doesn't exec work in a function with a subfunction?

It looks like you can't use exec in a function that has a subfunction... Anyone know why this Python code doesn't work? I get an error at the exec in test2. Also, I know exec's aren't good style, but trust me, I'm using exec for an appropriate…
anon
58
votes
7 answers

sh command: exec 2>&1

What will this command do? exec 2>&1
valodzka
56
votes
2 answers

I do not understand how execlp() works in Linux

I have spent the last 2 days trying to understand the execlp() system call, but yet here I am. Let me get straight to the issue. The man page of execlp declares the system call as int execlp(const char *file, const char *arg, ...); with the…
Arman Iqbal
  • 725
  • 2
  • 8
  • 14
54
votes
9 answers

Executing a Java application in a separate process

Can a Java application be loaded in a separate process using its name, as opposed to its location, in a platform independent manner? I know you can execute a program via ... Process process = Runtime.getRuntime().exec( COMMAND ); ... the main issue…
Ande Turner
  • 7,096
  • 19
  • 80
  • 107
54
votes
6 answers

Redirecting exec output to a buffer or file

I'm writing a C program where I fork(), exec(), and wait(). I'd like to take the output of the program I exec'ed to write it to file or buffer. For example, if I exec ls I want to write file1 file2 etc to buffer/file. I don't think there is a way…
devin
  • 6,407
  • 14
  • 48
  • 53
54
votes
3 answers

How to get local variables updated, when using the `exec` call?

I thought this would print 3, but it prints 1: # Python3 def f(): a = 1 exec("a = 3") print(a) f() # 1 Expected 3
ubershmekel
  • 11,864
  • 10
  • 72
  • 89
53
votes
6 answers

Dynamic/runtime method creation (code generation) in Python

I need to generate code for a method at runtime. It's important to be able to run arbitrary code and have a docstring. I came up with a solution combining exec and setattr, here's a dummy example: class Viking(object): def __init__(self): …
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
52
votes
7 answers

python: get the print output in an exec statement

I want to get the output of an exec(...) Here is my code: code = """ i = [0,1,2] for j in i : print j """ result = exec(code) How could I get the things that print outputed? How can I get something like: 0 1 2 Regards and thanks.
Bussiere
  • 500
  • 13
  • 60
  • 119
52
votes
11 answers

How do I get the return value when using Python exec on the code object of a function?

For testing purposes I want to directly execute a function defined inside of another function. I can get to the code object of the child function, through the code (func_code) of the parent function, but when I exec it, i get no return value. Is…
user2433423
  • 521
  • 1
  • 4
  • 3
51
votes
10 answers

PHP exec - check if enabled or disabled

Is there a way to check in a php script if exec() is enabled or disabled on a server?
Adrian M.
  • 7,183
  • 15
  • 46
  • 54
50
votes
2 answers

Setting variables with exec inside a function

I just started self teaching Python, and I need a little help with this script: old_string = "didnt work" new_string = "worked" def function(): exec("old_string = new_string") print(old_string) function() I want to get it so…
Spacenaut
  • 549
  • 1
  • 4
  • 4
50
votes
7 answers

What is the difference between the functions of the exec family of system calls like exec and execve?

I have been following a system programming course recently and I came through the system calls exec() and execve(). So far I cannot find any difference between these two, Even the Wikipedia does not give a clear explanation, so is there a…
buddhi weerasinghe
  • 677
  • 2
  • 9
  • 17
49
votes
3 answers

PHP exec() not returning error message in output

I am trying to get certain output for svn command in XML format. Output is ok when I type valid parameters. However, when I type in wrong password, output does not show error message. This is the PHP code: exec('/usr/bin/svn --username something…
Goran
  • 3,292
  • 2
  • 29
  • 32
48
votes
4 answers

How to spawn parallel child processes on a multi-processor system?

I have a Python script that I want to use as a controller to another Python script. I have a server with 64 processors, so want to spawn up to 64 child processes of this second Python script. The child script is called: $ python create_graphs.py…
tatlar
  • 3,080
  • 2
  • 29
  • 40
48
votes
7 answers

How to retrieve PHP exec() error responses?

Below is the command I tried executing, without success: exec('ln -s ' . PLUGIN_DIR . '/.htaccess ' . ABSPATH . '/.htaccess'); When you add a die() at the end, it catches that there's an error: exec('ln -s ' . PLUGIN_DIR . '/.htaccess ' . ABSPATH .…
Matt
  • 3,778
  • 9
  • 35
  • 36