subprocess

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python's subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What's the most direct / Haskellish way to do this? ...

How to get process's grandparent id

How can i get process id of the current process's parent? In general given a process id how can I get its parent process id? e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent, My target is linux(ubuntu) so platform specific answers are ok. ...

Detach a subprocess started using python multiprocessing module

Hello, I would like to create a process using the mutliprocessing module in python but ensure it continues running after the process that created the subprocess exits. I can get the required functionality using the subprocess module and Popen, but I want to run my code as a function, not as a script. The reason I want to do this is to ...

Run child processes as different user from a long running process

I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as a different user (e.g., "nobody") while retaining the super user privileges for the parent...

How to catch the ouput from a execl command

I'm using the execl function to run a Linux process from C. When I do, for example: int cmd_quem() { int result; result = fork(); if(result < 0) { exit(-1); } if (result == 0) { execl("/usr/bin/who", "who", NULL); sleep(4); //checking if father is being polite exit(1); } else { // father's time ...

Piping Cygwin into a Python program

Hello guys, As a i'm new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin's stdin & stdout into a python program usin Python's subprocess moudle. for example I took a simple program: cygwin = subprocess.Popen('PathToCygwin',shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE) cygwin.s...

How to call ssh by subprocess module so that it uses SSH_ASKPASS variable

I am writing a GUI which uses SSH commands. I tried to use the subprocess module to call ssh and set the SSH_ASKPASS environment variable so that my application can pop up a window asking for the SSH password. However I cannot make ssh read the password using the given SSH_ASKPASS command: it always prompts it in the terminal window, reg...

Launching default application for given type of file, OS X

I'm writing a python script that generates html file. Every time I run this script I'd like at the end to open default system browser for this file. It's all in OS X environment. What python code can launch Safari/Firefox/whatever is system default html viewer and open given file? subprocess.call doesn't seem to do the trick. ...

How to pass this command to subprocess.call?

Command: root@host:~#convert source.jpg -resize x500 -resize "500x<" -gravity center +repage target.jpg Python code: >> command_list = ['convert', 'source.jpg', '-resize', 'x500', '-resize', '\'500x<\'', '-gravity', 'center', 'target.jpg'] >> p = subprocess.call(command_list) convert: invalid argument for option `'500x<'': -resize. ...

Asynchronously read stdout from subprocess.Popen

I am running a sub-program using subprocess.popen. When I start my Python program from the command window (cmd.exe), the program writes some info and dates in the window as the program evolves. When I run my Python code not in a command window, it opens a new command window for this sub-program's output, and I want to avoid that. When...

Subprocess Popen and PIPE in Python

The following code prints an empty line as an output which is false. The problem is not in the permissions, since I tested the command with 777 permissions for the pdf -file. How can you fix the command to give a right output? import subprocess from subprocess import PIPE, Popen output = Popen(['pdftotext', '/home/aal/Desktop/lkn_pdf/ap...

Kill Windows asynchronous Popen process in 2.4

I have a testing script that needs to open a process (a Pyro server), do some stuff that will call the opened process for information, and when it's all done will need to close the process back down. It's all part of an automated test on a staging server. In python 2.6 you can do this: pyro_server = subprocess.Popen(['python', 'pyro_s...

How to set shell variables in subprocess.Popen (in a less ugly way...)

NOTE: This is not the same question as Python: Persistent shell variables in subprocess, as that question is actually about environment variables, not shell variables. I'm trying to automate a basic benchmark that I'm doing in csh using the shell built-in time command. You can tweak the output of time by setting the variable of the sam...

Python: get the return code of ant sub-process in windows

I use python to call ant, I want to get the return code of the ant for detect ant error. for example, in cmd.exe, C:\Documents and Settings\Administrator>ant sfsf Buildfile: build.xml does not exist! Build failed C:\Documents and Settings\Administrator>echo %ERRORLEVEL% 1 but in python: >>> a = subprocess.Popen("ant hahah",shell=Tr...

Python popen wont work with block devices

I am wring a small forensic app which looks like this so far import time, os,sys def getter(): filename = sys.argv[1] print "File Entered: " + filename os.system('file ' + filename) print "\n" pipe = os.popen("xxd " + filename, "r") print pipe.read() I input via the command line a file and it prints out the t...

Strip final 0 off a python string

#!/usr/bin/env python import os, sys, subprocess, time while True: print subprocess.call("xsel", shell=True); time.sleep(1); Takes an entry from the clipboard and prints it, every 1 second. Result: copied0 entry0 from0 clipboard0 I do not know why it returns the final 0, but it apparently stops me from using string stri...

PHP - 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 and run a command on it, and not have everything blow up. If PHP had an exec-type-function ...

Killing the child processes with the parent process

I have a program spawning and communicating with cpu heavy, unstable processes, not created by me. If my app crashes or is killed by sigkill, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually. I know this topic has been covered before, but I have tried all methods described, ...

Color a Button after subprocess has finished

I have a Tk python program that creates a list of python files in the current directory and generates a button for each of them. When you click a button the corresponding python program is launched via subprocess in a new gnome-terminal. I'd like to switch the button's color to red after the subprocess has finished executing on the new t...

Robocopy error code 6 ''The handle is invalid'

I have written a python script that uses subprocess to call robocopy to sync log files from a remote host. Like so: program = 'Robocopy' options = ['/S'] args.append(program) args.append(options) args.append('\\\\%s\%s' % (hostname, source_path)) args.append(local_path) proc = subprocess.Popen(args=args, shell=True, stdout=cmd_log, st...