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
48
votes
4 answers

Behavior of exec function in Python 2 and Python 3

Following code gives different output in Python2 and in Python3: from sys import version print(version) def execute(a, st): b = 42 exec("b = {}\nprint('b:', b)".format(st)) print(b) a = 1. execute(a, "1.E6*a") Python2 prints: 2.7.2…
Holger
  • 2,125
  • 2
  • 19
  • 30
47
votes
7 answers

How do you run a .bat file from PHP?

Can anyone tell me how to execute a .bat file from a PHP script? I have tried: exec("C:\[path to file]"); system("C:\[path to file]"); Nothing is working. I've checked the PHP manuals and googled around but can't find a good answer. Anyone know…
undefined
  • 5,190
  • 11
  • 56
  • 90
47
votes
2 answers

php exec() is not executing the command

I have tried to use exec() with 'whoami' to check if it works and I got the result of nt authority\system Now I need to run a .exe file with parameters from php via exec() function. I tried this in command prompt and it actually runs the program…
Brian
  • 4,958
  • 8
  • 40
  • 56
46
votes
3 answers

nodeJS exec does not work for "cd " shell cmd

var sys = require('sys'), exec = require('child_process').exec; exec("cd /home/ubuntu/distro", function(err, stdout, stderr) { console.log("cd: " + err + " : " + stdout); exec("pwd", function(err, stdout, stderr) { …
user1447121
  • 2,861
  • 4
  • 22
  • 23
46
votes
5 answers

Checking exec() runs successfully or not

I have been trying to let know know if the exec() command in php executes successfully or not so i can echo certain messages accordingly. I tried the following piece of code but the problem with it is that whether exec() runs successfully or not it…
soft genic
  • 2,016
  • 3
  • 27
  • 44
44
votes
11 answers

How to execute cmd commands via Java

I am trying to execute command line arguments via Java. For example: // Execute command String command = "cmd /c start cmd.exe"; Process child = Runtime.getRuntime().exec(command); // Get output stream to write from it OutputStream out =…
joe
  • 16,988
  • 36
  • 94
  • 131
44
votes
4 answers

What's the difference between escapeshellarg and escapeshellcmd?

PHP has 2 closely related functions, escapeshellarg() and escapeshellcmd(). They both seem to do similar things, namely help make a string safer to use in system()/exec()/etc. Which one should I use? I just want to be able to take some user input…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
43
votes
1 answer

Command to see 'R' path that RStudio is using

Original Question This seems easy and has likely been asked before, but I could not find it via a search. I have a few flavors of R installed. I simply want to know, when I run RStudio, which flavor of R is it pointing to. So, I need a command --…
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
42
votes
2 answers

What happens to malloc'ed memory after exec() changes the program image?

I know that when I call one of the exec() system calls in Linux that it will replace the currently running process with a new image. So when I fork a new process and run exec(), the child will be replaced with the new process. What happens to any…
Jonathan Sternberg
  • 6,421
  • 7
  • 39
  • 58
40
votes
1 answer

Need explanations for Linux bash builtin exec command behavior

From Bash Reference Manual I get the following about exec bash builtin command: If command is supplied, it replaces the shell without creating a new process. Now I have the following bash script: #!/bin/bash exec ls; echo 123; exit 0 This…
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
40
votes
4 answers

Dynamically filtering a pandas dataframe

I am trying to filter a pandas data frame using thresholds for three columns import pandas as pd df = pd.DataFrame({"A" : [6, 2, 10, -5, 3], "B" : [2, 5, 3, 2, 6], "C" : [-5, 2, 1, 8, 2]}) df = df.loc[(df.A > 0)…
ahoosh
  • 1,340
  • 3
  • 17
  • 31
39
votes
5 answers

How can I escape double-quotes in ant?

I need to exec the following command from ant, but I can't figure out how to escape the double-quotes: tasklist /FI "IMAGENAME eq java.exe" /FI "MEMUSAGE gt 50000"
sachin
  • 665
  • 3
  • 8
  • 15
39
votes
3 answers

How could I pass a dynamic set of arguments to Go's command exec.Command?

I came across a question on here relating to arguments being passed to Go's exec.Command function, and I was wondering if there was a way do pass these arguments dynamically? Here's some sample code from sed question: package main import…
Harry Lawrence
  • 783
  • 1
  • 7
  • 17
39
votes
3 answers

How do I execute a Shell built-in command with a C function?

I would like to execute the Linux command "pwd" through a C language function like execv(). The issue is that there isn't an executable file called "pwd" and I'm unable to execute "echo $PWD", since echo is also a built-in command with no executable…
user2851770
  • 393
  • 1
  • 3
  • 4
39
votes
6 answers

How to check if a shell command exists from PHP

I need something like this in php: If (!command_exists('makemiracle')) { print 'no miracles'; return FALSE; } else { // safely call the command knowing that it exists in the host system shell_exec('makemiracle'); } Are there any solutions?
mimrock
  • 4,813
  • 8
  • 32
  • 35