popen

How do I launch a file in its default program, and then close it when the script finishes?

 ̄綄美尐妖づ 提交于 2019-12-29 05:56:25
问题 Summary I have wxPython GUI which allows the user to open files to view. Currently I do this with os.startfile() . However, I've come to learn that this is not the best method, so I'm looking to improve. The main drawback of startfile() is that I have no control over the file once it has been launched. This means that a user could leave a file open so it would be unavailable for another user. What I'm Looking For In my GUI, it is possible to have children windows. I keep track of all of these

how to call a program from python without waiting for it to return

倾然丶 夕夏残阳落幕 提交于 2019-12-29 04:37:05
问题 is there a way to call a program from python without waiting for it to return? i created a script which copies a program to a directory and runs that program. but when i call the program from python, the python script does not exit until the program i launched exits. i have tried os.system and Popen. is there another way to do this? Added info: os.spawnl with os.P_DETACH still doesn't work; according to the docs, "P_DETACH is similar to P_NOWAIT, but the new process is detached from the

C-fopen,fwrite,fread,fseek,fgets,popen,access笔记

丶灬走出姿态 提交于 2019-12-27 14:58:36
FILE * fopen(const char * path,const char * mode); 所需库: <stdio.h> 返回值 FILE是C语言定义的标准数据结构,如果open()失败,则返回NULL path 路径 mode 打开模式,包括有以下几种 r 以只读方式打开文件,该文件必须存在。 r+ 以读/写方式打开文件,该文件必须存在。 rb+ 以读/写方式打开一个二进制文件,只允许读/写数据。 rt+ 以读/写方式打开一个文本文件,允许读和写。 w 打开只写文件,若文件存在则长度清为 0,即该文件内容消失,若不存在则创建该文件。 w+ 打开可读/写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。 a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留(EOF 符保留)。 a+ 以附加方式打开可读/写的文件。若文件不存在,则会建立该文件,如果文件存在,则写入的数据会被加到文件尾后,即文件原先的内容会被保留(原来的 EOF 符不保留)。 wb 以只写方式打开或新建一个二进制文件,只允许写数据。 wb+ 以读/写方式打开或建立一个二进制文件,允许读和写。 wt+ 以读/写方式打开或建立一个文本文件,允许读写。 at+ 以读/写方式打开一个文本文件,允许读或在文本末追加数据

How do I get all of the output from my .exe using subprocess and Popen?

寵の児 提交于 2019-12-27 12:05:01
问题 I am trying to run an executable and capture its output using subprocess.Popen ; however, I don't seem to be getting all of the output. import subprocess as s from subprocess import Popen import os ps = Popen(r'C:\Tools\Dvb_pid_3_0.exe', stdin = s.PIPE,stdout = s.PIPE) print 'pOpen done..' while: line = ps.stdout.readline() print line It prints two line less than the original exe file when opened manually. I tried an alternative approach with the same result: f = open('myprogram_output.txt',

link several Popen commands with pipes

北慕城南 提交于 2019-12-27 11:03:40
问题 I know how to run a command using cmd = subprocess.Popen and then subprocess.communicate. Most of the time I use a string tokenized with shlex.split as 'argv' argument for Popen. Example with "ls -l": import subprocess import shlex print subprocess.Popen(shlex.split(r'ls -l'), stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0] However, pipes seem not to work... For instance, the following example returns noting: import subprocess import shlex print

Cannot allocate memory on Popen commands

一世执手 提交于 2019-12-25 08:28:13
问题 I have a VPS server with Ubuntu 11.10 64bit and sometimes when I execute a subprocess.Popen command I get am getting too much this error: OSError: [Errno 12] Cannot allocate memory Config details: For each site I have an apache site like this: http://pastebin.com/mcew79sH And also a settings and a wsgi file (both on same folder than project) like this: http://pastebin.com/hrrV4WTM I am passing the arguments to Popen constructor as a list and using close_fds=True, I am also using and stdin

Get pid of recursive subprocesses

天大地大妈咪最大 提交于 2019-12-25 08:16:11
问题 Scenario: subprocess created a subprocess and so on, how can i get it's pid? I used subprocess.popen to launch the first subprocess, for example word file, this word file generated a new subprocess, how can i get it's pid? 回答1: Using psutil: parent = psutil.Process(parent_pid) children = parent.children() # all child pids can be accessed using the pid attribute child_pids = [p.pid for p in children] 来源: https://stackoverflow.com/questions/40509813/get-pid-of-recursive-subprocesses

Capturing tshark standard output with popen in C

自古美人都是妖i 提交于 2019-12-25 06:48:16
问题 I'm trying to capture the standard output from tshark through a program in C. For that, I use popen() call to open tshark process and read from the returned FILE stream. Code sample: #include <stdio.h> #include <stdlib.h> int main() { FILE* pipe_fd = popen("tshark -i eth0 -R icmp -2 -T fields -e icmp.checksum -e icmp.seq", "r"); //FILE* pipe_fd = popen("lsof", "r"); if (!pipe_fd) { fprintf(stderr, "popen failed.\n"); return EXIT_FAILURE; } char buffer[2048]; while (NULL != fgets(buffer,

popen handle across persistent connections

南楼画角 提交于 2019-12-25 06:38:50
问题 I am trying to execute a command by using popen and then print out its progress via AJAX. I have found this post extremely helpful and got the AJAX to script exchange working fine. The problem is that every time there is an async GET to test from ajax, the handle on popen is repeated. If I have the shell only run once, then the handle is no longer valid. I can't figure out how to make $handle be persistent accross requests. public function test() { chdir('my dir'); $handle = popen('make

Disk Defrag and Disk Clean up using Python Script

北城以北 提交于 2019-12-25 04:26:19
问题 Can you help me on how to make this script work. For Defrag import os; defragmentation=os.popen('defrag.exe /C').read() print(defragmentation); For Disk Clean up import os; clean=os.popen('cleanmgr.exe /sagerun:1').read() print(clean); Upon trying this scripts, it didnt do anything and no error message prompt. Thank you. 回答1: If your defrag.exe or cleanmgr.exe are not in your path , they won't execute and you won't get an error message You would need to run the scripts as an administrator to