os.system

python or bash script to pass all files in a folder to java command line

岁酱吖の 提交于 2019-12-06 15:38:01
I have the following Java command line working fine Mac os. java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer file.txt > output.txt Multiple files can be passed as input with spaces as follows. java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer file1.txt file2.txt > output.txt Now I have 100 files in a folder. All these files I have to pass as input to this command. I used python os.system in a for loop of directories as follows . for i,f in enumerate(os.listdir(filedir)): os.system('java -cp "stanford-ner.jar" edu.stanford.nlp.process.PTBTokenizer "%s" > "annotate_

how to use os.system() in python for running an shell order

心不动则不痛 提交于 2019-12-06 09:18:53
问题 In some shell script, you need to confirm "yes" to run the shell, well, an easier way is using "yes" and pipe, like this: yes | test.py then, you can run the shell script automatically without answer "yes" anymore. today, when i use this in python by trying : os.system("yes|**.sh"), i got an fault. Here is my test.py file: import os def f(): cmd1 = "yes | read " os.system(cmd1) f() and run in shell by typing : python test.py. the fault information is : yes: standard output: Broken pipe yes:

Wait for child using os.system

时光怂恿深爱的人放手 提交于 2019-12-06 08:03:33
I use a lot of os.system calls to create background processes inside a for loop. How can I wait for all the background processes to end ? os.wait tells me there are no child process. ps: I am using Solaris here is my code : #!/usr/bin/python import subprocess import os pids = [] NB_PROC=30 for i in xrange(NB_PROC): p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True) pids.insert(0,p) p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True) pids.insert(0,p) for i in xrange(NB_PROC*2): pids[i].wait() os.system("rm test.php

Why does this triple quoting solution fix path error?

雨燕双飞 提交于 2019-12-06 05:53:05
So I was running into a bit of a problem today with this bit of code: os.system("C:\Program Files (x86)\DOSBox-0.72\dosbox.exe") Upon execution I'd get this error message: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. I assumed it was something to do with either the white space or the brackets, so I did a bit of digging online and after countless of ineffective "solutions" involving escape characters, I ended up finding a rather strange solution; to surround the double quotes with another double and a single like so: os.system('""C:\Program

Pyinstaller - Calling GDAL from os.system (gdal_translate)

两盒软妹~` 提交于 2019-12-06 04:28:36
Greetings learned fellows. Running 32bit Python2.7 on Windows 7. I'm have a question regarding including GDAL executables in a pyinstaller build. I am making a system call to run two GDAL functions from the FWTools release. These functions are in the PATH variable on windows C:\Program Files (x86)\FWTools2.4.7\bin and so it runs fine from the Python27 environment. However, this path is not carried over to the pyinstaller build. The code in question is calling a GDAL function to re-translate an image onto different geospatial co-ordinates. os.system("gdal_translate -of GTiff -a_ullr 694440.7939

How to determine pid of process started via os.system

谁都会走 提交于 2019-12-05 05:27:09
I want to start several subprocesses with a programm, i.e. a module foo.py starts several instances of bar.py . Since I sometimes have to terminate the process manually, I need the process id to perform a kill command. Even though the whole setup is pretty “dirty”, is there a good pythonic way to obtain a process’ pid , if the process is started via os.system ? foo.py: import os import time os.system("python bar.py \"{0}\ &".format(str(argument))) time.sleep(3) pid = ??? os.system("kill -9 {0}".format(pid)) bar.py: import time print("bla") time.sleep(10) % within this time, the process should

Give response yes/no in python when a command is executed os.system() in python linux

▼魔方 西西 提交于 2019-12-04 20:08:48
Consider a command like yum install boto When I execute in terminal, to proceed is asks me for yes/no Can I respond to it in python like os.system("yum install boto") Next "Yes" is to be passed to terminal through the same python code so that it installs. Well, I dont think this works. If it is written after tha above statement os.system("yes") Please tell me if this is possible? You can use subprocess.Popen and write to stdin, you need the -S flag for sudo then just the rest of the commands. from subprocess import Popen, PIPE import getpass pwd = getpass.getpass() proc = Popen(['sudo', '-S',

how to use os.system() in python for running an shell order

℡╲_俬逩灬. 提交于 2019-12-04 17:27:36
In some shell script, you need to confirm "yes" to run the shell, well, an easier way is using "yes" and pipe, like this: yes | test.py then, you can run the shell script automatically without answer "yes" anymore. today, when i use this in python by trying : os.system("yes|**.sh"), i got an fault. Here is my test.py file: import os def f(): cmd1 = "yes | read " os.system(cmd1) f() and run in shell by typing : python test.py. the fault information is : yes: standard output: Broken pipe yes: write error but if i type "yes|read" in shell,it works well. may anyone tell me why? try this import os

Python threads with os.system() calls. Main thread doesn't exit on ctrl+c

久未见 提交于 2019-12-04 10:12:09
Please don't consider it a duplicate before reading, There are a lot of questions about multithreading and keyboard interrupt , but i didn't find any considering os.system and it looks like it's important. I have a python script which makes some external calls in worker threads. I want it to exit if I press ctrl+c But it look like the main thread ignores it. Something like this: from threading import Thread import sys import os def run(i): while True: os.system("sleep 10") print i def main(): threads=[] try: for i in range(0, 3): threads.append(Thread(target=run, args=(i,))) threads[i].daemon

Python 'source HOME/.bashrc' with os.system()

痴心易碎 提交于 2019-12-04 04:58:49
I am writing a python script (Linux) that is adding some shell aliases (writes them to HOME/.bash_aliases ). In order to make an alias available immediately after it was written I should issue the following bash built-in: source HOME/.bashrc source is a bash built-in so I cannot just: os.system(source HOME/.bashrc) If i try something like: os.system('/bin/bash -c source HOME/.bashrc') ...will freeze the script (just like is waiting for something). Any suggestions ? What you want is not possible. A program (your script) cannot modify the environment of the caller (the shell you run it from).