I have couple of file with same name, and I wanted to get the latest file [
[email protected] tmp]# ls -t1 abclog* abclog.1957 abclog.1830 abclog.1799 abclog.1742 I can accomplish that by executing below command. [
[email protected] tmp]# ls -t1 abclog*| head -n 1 abclo
I am writing a watchdog, of sorts, for processes in a test suite. I need to determine if a test hangs. I could simply start the process with subprocess.Popen(...), and use Popen.wait(timeout=to) or Popen.poll() and keep my own timer. However, the tes
I want to run a python function,say my_fun(x1,x2), on different nodes of cluster with SGE (QSUB). I created a script my_script.py which takes in the numeric arguments from the command line, so when running locally, I'd call it as python my_script.py
I have the following Python 2 example code that I want to make compatible with Python 3: call = 'for i in {1..5}; do sleep 1; echo "Hello $i"; done' p = subprocess.Popen(call, stdout=subprocess.PIPE, shell=True) for line in iter(p.stdout.readlin
I am unable to print an output statement in a single line from cli. The line breaks down into 3 lines. I tried printing it using print function and then tried print with a comma like print "......", and now I am using format style but none of th
If I have a function in a file like this: def foo(): print 'foo' foo() I can call this file from another one: import subprocess subprocess.call(['python', 'function.py']) But can if the function needs arguments: def foo(foo_var): print foo_var Can I
How do I get the output from a command using subprocess.Popen and have separate callbacks for stdout and stderr, but ensure that those callbacks are called in the order that the lines came from the process? If I didn't care about separating out STDOU
My system is composed of a python application that is launched from supervisord. Let's call it A. A launches a subprocess B to do some of its task. Both A and B are coded in Python and use the standard logging module to output messages to the console
If I run a terminal command from Python using subprocess, how do I print the password prompt? I have a Python script that asks users to authenticate via Kerberos. My program is basically this: import subprocess def kinit(): kinit = "kinit -f" pr
I am trying to execute an external command inpython. The command arguments , if executed in the shell are as follows: osmconvert inputfile -b=bbox -o=outputfile I am trying to call it with subprocess as fowlloows: import subprocess as sb inputfile =
In the program I maintain it is done as in: # count the files in the archive length = 0 command = ur'"%s" l -slt "%s"' % (u'path/to/7z.exe', srcFile) ins, err = Popen(command, stdout=PIPE, stdin=PIPE, startupinfo=startupinfo).communica
I have this code: def __executeCommand(self, command: str, input: str = None) -> str: p = sub.Popen(command, stdout=sub.PIPE, stderr=sub.PIPE, stdin=sub.PIPE, universal_newlines=True) p.stdin.write(input) output, error = p.communicate() if (len(error
I'm trying to compress some files with python. I'm using subprocess, the problem is that I don't know how to compress all the files. Here is what I do: comand = czf saveFolder = /home/albert/a.tgz temporal = /home/albert/test1 subprocess.call(["tar&q
This question already has an answer here: Retrieving the output of subprocess.call() 7 answers Newbie in python. I'm trying to call a python script from a python script, for most of which I'm successful except capturing the result. a.py status = subp
I can't figure out how to close a bash shell that was started via Popen. I'm on windows, and trying to automate some ssh stuff. This is much easier to do via the bash shell that comes with git, and so I'm invoking it via Popen in the following manner
The following code shows error import sqlite3 as lite import sys con = lite.connect('test.db') url=http://www.google.com with con: cur = con.cursor() cur.execute("CREATE TABLE info(Id INT, Url_Name varchar(55))") cur.execute("INSERT INTO in
This has probably been asked but I cannot find anything regarding a subprocess.call timeout when using python 2.7A simple way I've always done timeouts with 2.7 is utilizing subprocess.poll() alongside time.sleep() with a delay. Here's a very basic e
I am trying to call a Python script from another. I am using the subprocess-module and calling it like this: subprocess.call(["python","script.py","parameter_name parameter_value"], shell=False) The thing is when I call it th
I have looked at Calling an external command in Python and tried every possible way with subprocess and os.popen but nothing seems to work. If I try import os stream = os.popen("program.ex -f file.dat | grep fish | head -4") I get lines and line
I'm playing with my Raspberry Pi GPIO. I connect 4 switch to GPIO. I want to realize the function is While hold switch 1. Stop the current movie, Play M01.mp4. While hold switch 2. Stop the current movie, Play M02.mp4. ... If no switch was holded, pl
This question already has an answer here: Convert bytes to a string? 13 answers I dont know what is happening, but when I am printing to the console or to a text file, the newline (\n) is not functioning but rather showing in the string. Any idea how
Executing this in shell gets me tangible results: wget -O c1 --no-cache "http://some.website" | sed "1,259d" c1 | sed "4,2002d" Doing this in Python gets me nothing: subprocess.call(shlex.split("wget -O c1 --no-cache \&q
I'm trying to write a simple program in Python that takes all the music files from my Downloads folder and puts them in my Music folder. I'm using Windows, and I can move the files using the cmd prompt, but I get this error: WindowsError: [Error 2] T
So I have some fairly gigantic .gz files - we're talking 10 to 20 gb each when decompressed. I need to loop through each line of them, so I'm using the standard: import gzip f = gzip.open(path+myFile, 'r') for line in f.readlines(): #(yadda yadda) f.
I've got 2 files main.py and infinit.py, like below: main.py #!/usr/bin/python import logging import subprocess import sys logging.basicConfig(level=logging.INFO) def forever(): cmd = [sys.executable, 'infinit.py'] while 1: try: print 'running new in
I have a unicode filename that I would like to open. The following code: cmd = u'cmd /c "C:\\Pok\xe9mon.mp3"' cmd = cmd.encode('utf-8') subprocess.Popen(cmd) returns >>> 'C:\Pok×™mon.mp3' is not recognized as an internal or external comm
Question: Can I use the multiprocessing module together with gevent on Windows in an efficient way? Scenario: I have a gevent based Python application doing asynchronous I/O on Windows. The application is mostly I/O bound, but there are spikes of hig
I'm having a hard time getting what I want out of the python subprocess module (which supposed to an unified/platform-independent abstraction, afaik, but don't get me started on that :)). So the simple thing what I'm after is the following. I want to
I am using the subprocess module to call an external program (plink.exe) to log-in to a server; but when I call communicate to read the output, it is blocking. The code is below: import subprocess process = subprocess.Popen('plink.exe
[email protected]
Update: When I use the subprocess.call instead of subprocess.Popen, the problem is solved - does anybody know what's the cause? And there came another problem: I can't seem to find a way to control the output... Is there a way to redirect the output