I'm trying to do some scripting, but one of the utilities I have returns a value to stdout, where I would like to assign it to a variable.
The utility (candump) is constantly running and only prints to std out when it receives data.
import threading
from subprocess import call
import time
class ThreadClass(threading.Thread):
def run(self):
call(["candump","can0"])
t = ThreadClass()
t.sta
I'm using subprocess.Popen with Python, and I haven't come across an elegant solution for joining commands (i.e.
Following is the code:
import subprocess
import re
#stores partitions from df command in df_partition list
p = subprocess.Popen("df -h", stdout=subprocess.PIPE, shell=True)
dfdata, _ = p.communicate()
dfdata = dfdata.replace("Mounted on", "")
columns = [list() for i in range(10)]
for line in dfdata.split("\n"):
line = re.sub(" +", " ", line)
for i,l in enumerate(line.split("
Hi. I'm having trouble writing a wrapper script for the command line text editor gnu ed.
I want to be able to run the following algorithm on ed:
1. Display, on stdout, a command which I intend to feed into ed (before I actually feed it to ed).
2. Actually feed the command into ed's stdin.
3.
I've read a bunch of examples but none of them work for this specific task.
Python code:
x = Popen(commands, stdout=PIPE, stderr=PIPE, shell=True)
print commands
stdout = x.stdout.read()
stderr = x.stderr.read()
print stdout, stderr
return stdout
Output:
[user@host]$ python helpers.py
['ssh', '-t', 'user@host', ' ', "'service --status-all'"]
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_ad
I am messing around with Django. I have a custom admin script in one of my apps (inside the management/commands folder) that has a subprocess.call() line. I am doing a 'sort A.csv -o A_sorted.csv' call. The sorted file that gets written is full of '^M' at the end of every line.
I'm puzzled by this one. If I'm connected to the network on a linux system everything works fine.
I am trying to install Python 3.2 and mod_wsgi on my web server, but I am not having much luck.
I run Raspbian Wheezy on my Raspberry Pi, and i want to call a Python script from PHP.
That all works great (i call 'exec python go.py' from php) but now i want to call a script which needs root rights.
I understood that running as root would help me out here ('exec sudo python go2.py', so i added this line of code to my sudo file
%www-data ALL=(ALL) NOPASSWD: ALL
ok, and now it works again.