communicate

Python's Popen + communicate only returning the first line of stdout

隐身守侯 提交于 2021-02-07 20:29:50
问题 I'm trying to use my command-line git client and Python's I/O redirection in order to automate some common operations on a lot of git repos. (Yes, this is hack-ish. I might go back and use a Python library to do this later, but for now it seems to be working out ok :) ) I'd like to be able to capture the output of calling git. Hiding the output will look nicer, and capturing it will let me log it in case it's useful. My problem is that I can't get more than the first line of output when I run

Python Capture reply from powershell

限于喜欢 提交于 2019-12-31 05:15:12
问题 The code below works when typed manually however when I run the program.py nothing prints. My ultimate goal is to retrieve this data from user pc to create an easy way to recreate shortcuts.... My users somehow lose them lol import smtplib, os, subprocess, sys from string import ascii_uppercase from cStringIO import StringIO data = os.popen(r"dir %userprofile%\desktop\*.lnk* /s/b").read() file = open("testitem.txt", "w") file.write(data) file.close() my_data = dict(zip(ascii_uppercase,open(

How to open a file in a new process everytime irrespective of fileopener

醉酒当歌 提交于 2019-12-23 18:45:02
问题 I am using windows 7 64 bit python 2.7 I am opening the file, and monitoring the file changes and then waiting till the opened file is closed. This works well in case of simple notepad file opener. As notepad opens each files in a new process ID whereas notepad++ opens different files in a single notepad++ process ID. ACTIONS = { 1 : "Created", 2 : "Deleted", 3 : "Updated", 4 : "Renamed from something", 5 : "Renamed to something" } FILE_LIST_DIRECTORY = 0x0001 class myThread (threading.Thread

Python subprocess with stdout redirect returning an int

不问归期 提交于 2019-12-22 06:35:36
问题 I am trying to read out data from a set of print statements in a C++ program that is being run using a subprocess. C++ code: printf "height= %.15f \\ntilt = %.15f \(%.15f\)\\ncen_volume= %.15f\\nr_volume= %.15f\\n", height, abs(sin(tilt*pi/180)*ring_OR), abs(tilt), c_vol, r_vol; e; //e acts like a print Python code: run = subprocess.call('Name', stdout = subprocess.PIPE, env={'LANG':'C++'}) data, error = run.communicate() However instead of getting the data, all I am getting is a single int,

how to communicate with R through VBnet( or C#)

痞子三分冷 提交于 2019-12-19 08:54:10
问题 Recently, I Developed an Experiment Application with VB.net(in Windows platform), When the application collected the data,I want to use R to Analysis the data, But I don't know how to Communicate with R (In other word, I want to send R script to R in my own application ). I will appreciate if anyone could give me some suggetions or some reference documents. Thank you very much! 回答1: I'd suggest you try R.NET. The blurb says: R.NET enables .NET Framework to collaborate with R statistical

Python subprocess Popen.communicate() equivalent to Popen.stdout.read()?

…衆ロ難τιáo~ 提交于 2019-12-17 22:09:34
问题 Very specific question (I hope): What are the differences between the following three codes? (I expect it to be only that the first does not wait for the child process to be finished, while the second and third ones do. But I need to be sure this is the only difference...) I also welcome other remarks/suggestions (though I'm already well aware of the shell=True dangers and cross-platform limitations) Note that I already read Python subprocess interaction, why does my process work with Popen

Understanding Popen.communicate

人盡茶涼 提交于 2019-12-17 03:03:42
问题 I have a script named 1st.py which creates a REPL (read-eval-print-loop): print "Something to print" while True: r = raw_input() if r == 'n': print "exiting" break else: print "continuing" I then launched 1st.py with the following code: p = subprocess.Popen(["python","1st.py"], stdin=PIPE, stdout=PIPE) And then tried this: print p.communicate()[0] It failed, providing this traceback: Traceback (most recent call last): File "1st.py", line 3, in <module> r = raw_input() EOFError: EOF when

Understanding Popen.communicate

流过昼夜 提交于 2019-12-17 03:03:23
问题 I have a script named 1st.py which creates a REPL (read-eval-print-loop): print "Something to print" while True: r = raw_input() if r == 'n': print "exiting" break else: print "continuing" I then launched 1st.py with the following code: p = subprocess.Popen(["python","1st.py"], stdin=PIPE, stdout=PIPE) And then tried this: print p.communicate()[0] It failed, providing this traceback: Traceback (most recent call last): File "1st.py", line 3, in <module> r = raw_input() EOFError: EOF when

Python Communicate/Wait with a shell subprocess

时光怂恿深爱的人放手 提交于 2019-12-12 04:56:56
问题 Tried searching for the solution to this problem but due to there being a command Shell=True (don't think that is related to what I'm doing but I could well be wrong) it get's lots of hits that aren't seemingly useful. Ok so the problem I is basically: I'm running a Python script on a cluster. On the cluster the normal thing to do is to launch all codes/etc. via a shell script which is used to request the appropriate resources (maximum run time, nodes, processors per node, etc.) needed to run

Python subprocess communicate kills my process

故事扮演 提交于 2019-12-11 03:00:47
问题 Why does communicate kill my process? I want an interactive process but communicate does something so that I cannot take raw_input any more in my process. from sys import stdin from threading import Thread from time import sleep if __name__ == '__main__': print("Still Running\n") x = raw_input() i = 0 while ('n' not in x ) : print("Still Running " + str(i) + " \r\n") x = raw_input() i += 1 print("quit") print(aSubProc.theProcess.communicate('y')) print(aSubProc.theProcess.communicate('y'))