os.system

how to close remote desktop window using python

☆樱花仙子☆ 提交于 2019-12-11 05:17:28
问题 I want to automate closing the remote desktop application using python. I open the remote desktop using mstsc. When I do os.system("TASKKILL /F /IM mstsc.exe") It is killing all the remote desktop applications that are open. Is there a way I can specify through python which remote desktop it has to close. I have 2 or more instances of remote desktop open and I require my program to close only specific connection. Is there a way I can pass the IP address or process ID or something. 回答1: To

Execute .jar from Python

 ̄綄美尐妖づ 提交于 2019-12-11 03:56:43
问题 I am trying to build a very simple python script to automate minifying/combining some css/js assets. I am not sure how to properly handle the minification step. I use yui-compressor and usually call the jar directly from the command line. Assuming the build script is in the same directory as rhino js.jar and yui-compressor.jar , I'd be able to compress a css/js file like so: java -cp js.jar -jar yuicompressor-2.4.4.jar -o css/foo.min.css css/foo.css Calling that from the terminal works fine,

store Os.system result in variable

自古美人都是妖i 提交于 2019-12-10 23:24:10
问题 hello guys i'm wondering how to store os.system result in variable as we know it's return 0 so i'm wondering what i should do to store the result and second question : how to get ip in Linux [ somebody will suggest ifconfig ] but ifconfig show so many result i just wana the IP 回答1: import os from subprocess import * def run_cmd(cmd): p = Popen(cmd, shell=True, stdout=PIPE) output = p.communicate()[0] return output As for the second question, see http://www.cyberciti.biz/tips/read-unixlinux

how to execute 7zip commands from python script

不问归期 提交于 2019-12-10 19:37:12
问题 I am trying to get a basic idea of how the os.system module can be used to execute 7zip commands. For now I don't want to complicate things with Popen or subprocess. I have installed 7zip and copied the 7zip.exe into my users folder. I just want to extract my test file install.zip. However using the code below causes the shell to appear briefly before exiting and no unzip has occurred. Please could you tell me why? def main(): try: os.system(r"C:\Users\Oulton\ 7z e C:\Users\Oulton\install.zip

Why does this triple quoting solution fix path error?

左心房为你撑大大i 提交于 2019-12-10 11:33:41
问题 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

How to determine pid of process started via os.system

泪湿孤枕 提交于 2019-12-10 04:08:16
问题 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

Start local PHP script w/ local Python script

旧时模样 提交于 2019-12-09 03:54:28
问题 The Python program I'm writing needs to start a local PHP script outside of Python's process. The program also needs to pass params to the PHP script. So far this seems to start the script: os.system( path_to_script_here param param ) However, I'm pretty certain that Python remains running until the PHP script is complete. I've also looked at the various os.spawn methods and I'm not sure which would be appropriate for my case. Any ideas? Thanks! 回答1: See: How to start a background process in

Python code to send command through command line

与世无争的帅哥 提交于 2019-12-08 09:03:29
问题 final="cacls " + "E:/" + "\"" + list1[2] + " " + list1[3] + "\"" + " /p " + str os.system(final) I am trying to set permission to a folder Using Python but while running this command , User input needs to be provided too i.e it asks ARE YOU SURE(Y/N) and the user needs to enter "Y" or "N" Is there any way to use python to send the user input "Y" along with the above code? pro = subprocess.Popen(final,shell=True, stdin=subprocess.PIPE) pro.communicate(bytes("Y\r\n",'utf-8')) I have added the

Subprocess - using several command line tools

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:59:46
问题 I'm a learning newbie to python and to working in the command line, e.g. piping. I've read that subprocess is encouraged way instead of os.system. I'm creating a script which invokes the shell and I have not been able to do it using subprocess. Using os.system was a snap though: os.system("cut -f1-4 " + temp1.name + "| uniq --count | sort -rn > " + temp2.name) I've used subprocess with success for other commands, but not those that combine more than one tools with "|". Reading the subprocess

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

夙愿已清 提交于 2019-12-08 05:42:29
问题 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