os.system

Wait for child using os.system

泄露秘密 提交于 2019-12-22 21:16:03
问题 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

run a python script everytime the computer wakes up from hibernation

半世苍凉 提交于 2019-12-21 05:39:13
问题 i wrote a small script on python that calls a command line from the console in order to hibernate a linux machine (or shut itself down in case one word is changed) and then wake up after some time. The command is called again again and again through the watch command. import os import time os.system("watch -n 20 sudo rtcwake -u -s 10 -m mem") So the rtcwake command is called again 20 seconds after the pc has wokn up again. I would like another script to be run every time the computer wakes up

Python os.system without the output

不打扰是莪最后的温柔 提交于 2019-12-18 03:53:35
问题 I'm running this: os.system("/etc/init.d/apache2 restart") It restarts the webserver, as it should, and like it would if I had run the command directly from the terminal, it outputs this: * Restarting web server apache2 ... waiting [ OK ] However, I don't want it to actually output it in my app. How can I disable it? Thanks! 回答1: Avoid os.system() by all means, and use subprocess instead: with open(os.devnull, 'wb') as devnull: subprocess.check_call(['/etc/init.d/apache2', 'restart'], stdout

Advantages of subprocess over os.system

纵然是瞬间 提交于 2019-12-17 19:19:23
问题 I have recently came across a few posts on stack overflow saying that subprocess is much better than os.system, however I am having difficulty finding the exact advantages. Some examples of things I have run into: https://docs.python.org/3/library/os.html#os.system "The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function." No idea in what ways it is more powerful though, I know it

Redirecting stdio from a command in os.system() in Python

…衆ロ難τιáo~ 提交于 2019-12-17 07:35:19
问题 Usually I can change stdout in Python by changing the value of sys.stdout . However, this only seems to affect print statements. So, is there any way I can suppress the output (to the console), of a program that is run via the os.system() command in Python? 回答1: You could consider running the program via subprocess.Popen , with subprocess.PIPE communication, and then shove that output where ever you would like, but as is, os.system just runs the command, and nothing else. from subprocess

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

妖精的绣舞 提交于 2019-12-14 03:41:04
问题 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 ? 回答1: What you want is not

How to handle an executable requiring interactive responses?

大憨熊 提交于 2019-12-13 18:34:12
问题 I have a executable, called tsfoil2.exe, and I want to operate this .exe from my python environment. I'm running Python 2.7.3, with Spyder 2.1.11 on Windows 7. In order to operate the .exe, it requires some input, the default hard drive ('I:\'), a name for the outputfile ('test'), and a name for the input file ('SC20610.inp'). One of my colleagues advised me to use os.system, and supply this with a temporary input file, that contains all the arguments. f = open('temp', 'w') f.write('I:\ \n')

How can I get Python to plugin my password and Username for an .exe file it opened

心已入冬 提交于 2019-12-12 05:05:41
问题 Hey guys I'm new to programming and I would appreciate some help. My program can open an application I have but to enter the application it requires a password and username which I don't know how to make my program plug in automatically. os.system('"C:\\abc\\123\\Filepath\\File.exe"') After the code opens the program of the .exe file how do I make it to where it can than automatically plug in the username and password for the application. Please and Thank you 回答1: What you need is Pywinauto,

os.system (old python) and arguments with parameters

余生颓废 提交于 2019-12-11 08:19:02
问题 I trying to write simple code that execute os command with parameters #!/usr/bin/env python # -*- coding: utf-8 -*- import os target = "i586" build = os.system('/usr/bin/hsh --target="target"') But it always start as /usr/bin/hsh --target=target instead of target=i586. Also subprocess.call not working cause python too old. Please help me. 回答1: build = os.system('/usr/bin/hsh --target="%s"' % target) or build = os.system('/usr/bin/hsh --target="' + target + '"') 来源: https://stackoverflow.com

Use os.system to launch executable from path assigned to a variable?

China☆狼群 提交于 2019-12-11 06:59:47
问题 first time asking a question here. What I am trying to do is launch an executable with os.system after the exe path has been assigned to a variable, and having os.system open the path assigned to the variable. It works fine if I have just the path pasted in the parenthesis (with the quotes ofc) but when I only have the variable there, it does not launch anything. I have tried the print function on the same variable and it prints the path out correctly. Here is what I have that creates the