Dear all
I have tkinkter based frontend to a Fortran based program. I use
subprocess to launch the fortran program as a child process and I wish
to see the output of the fortran program as it is created in the
console.
The fortran program can take up to 20 minuttes to finish and at the
moment the I will first see any output after the fortran program is
done. How make my function write the output of the process as it
comes?
def runprogram(Icom mand, Ijobfile, Ioutput):
if os.name == "posix":
os.system(pytho npath+"/bin/"+Icommand+ "< "+Ijobfile+ " | tee
"+Ioutput)
elif os.name == "nt":
import subprocess
ofile = open(Ioutput, 'w')
p = subprocess.Pope n([os.path.join(py thonpath, "bin", Icommand
+ '.exe')],
stdin=open(Ijob file,
"rb"),bufsize=1 024,shell=False ,
stdout=subproce ss.PIPE)
while p.poll() is None: #Check if child process has terminated.
o = p.stdout.readli ne()
ofile.writeline s(o)
print o,
ofile.close
Kind regards
Thomas Jansson 3 2396
On Sep 8, 8:37*am, Thomas Jansson <tjansso...@gma il.comwrote:
Dear all
I have tkinkter based frontend to a Fortran based program. I use
subprocess to launch the fortran program as a child process and I wish
to see the output of the fortran program as it is created in the
console.
The fortran program can take up to 20 minuttes to finish and at the
moment the I will first see any output after the fortran program is
done. How make my function write the output of the process as it
comes?
def runprogram(Icom mand, Ijobfile, Ioutput):
* * if os.name == "posix":
* * * * os.system(pytho npath+"/bin/"+Icommand+ "< "+Ijobfile+ " | tee
"+Ioutput)
* * elif os.name == "nt":
* * * * import subprocess
* * * * ofile = open(Ioutput, 'w')
* * * * p = subprocess.Pope n([os.path.join(py thonpath, "bin", Icommand
+ '.exe')],
* * * * * * * * * * * * * * *stdin=open(Ijo bfile,
"rb"),bufsize=1 024,shell=False ,
* * * * * * * * * * * * * * *stdout=subproc ess.PIPE)
* * * * while p.poll() is None: #Check if child process has terminated.
* * * * * * o = p.stdout.readli ne()
* * * * * * ofile.writeline s(o)
* * * * * * print o,
* * * * ofile.close
Kind regards
Thomas Jansson
import threading, Queue, subprocess
class iCommand(thread ing.Thread):
def __init__ (self, iCommand, iJobFile, queue):
threading.Threa d.__init__(self )
self.iCommand = iCommand
self.queue = queue
self.iJobFile = iJobFile
def run(self):
p = subprocess.Pope n([os.path.join("C :/Python25", "bin",
self.iCommand + '.exe')],
stdin=open(self .iJobFile,
"rb"),bufsize=1 024,shell=False ,
stdout=subproce ss.PIPE)
while p.poll() == None:
q.put(p.stdout. readline())
command = "FOO"
jobFile = ="FAH"
aQueue = Queue.Queue()
fo = open("C:/temp/foo.out", 'w')
aThread = iCommand(comman d, jobFile, aQueue)
aThread.start()
while aThread.isAlive () or not aQueue.empty():
l = aQueue.get().rs trip()
fo.write(l)
print l
fo.close()
A bit of fun for a sleepless night...
~Sean
Sean DiZazzo wrote:
while aThread.isAlive () or not aQueue.empty():
l = aQueue.get().rs trip()
fo.write(l)
print l
fo.close()
A bit of fun for a sleepless night...
and unless you add a call to time.sleep somewhere in that loop, you'll
keep your CPU up all night as well...
</F>
On Sep 8, 5:37*pm, Thomas Jansson <tjansso...@gma il.comwrote:
Dear all
I have tkinkter based frontend to a Fortran based program. I use
subprocess to launch the fortran program as a child process and I wish
to see the output of the fortran program as it is created in the
console.
The fortran program can take up to 20 minuttes to finish and at the
moment the I will first see any output after the fortran program is
done. How make my function write the output of the process as it
comes?
Sometimes very low technology solutions may be enough. For instance on
Unix
you could call os.system on something like that:
xterm -e "the-fortran-executable|less "
Make sure the Fortran executable output is unbuffered.
Michele Simionato This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Darren Dale |
last post by:
I'm a developer on the matplotlib project, and I am having trouble with the
subprocess module on windows (Python 2.4.2 on winXP). No trouble to report
with linux. I need to use _subprocess instead of pywin32, but my trouble
exists with either option:
import subprocess
process = subprocess.Popen(, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE)
stat = process.wait()
print process.stdout.read()
|
by: Fuzzyman |
last post by:
Hello all,
Before I ask the question a couple of notes :
* This question is for implementing a script inside the Wing IDE. For
some reason using the subprocess module doesn't work so I need a
solution that doesn't use this module.
* The platform is Windows and I'm happy with a Windoze only solution.
:-)
|
by: Tom Plunket |
last post by:
I'm using subprocess to launch, well, sub-processes, but now I'm
stumbling due to blocking I/O.
Is there a way for me to know that there's data on a pipe, and possibly
how much data is there so I can get it? Currently I'm doing this:
process = subprocess.Popen(
args,
bufsize=1,
universal_newlines=True,
|
by: bayer.justin |
last post by:
Hi,
I am trying to communicate with a subprocess via the subprocess
module. Consider the following example:
<subprocess.Popen object at 0x729f0>
Here hey is immediately print to stdout of my interpreter, I did not
type in the "hey". But I want to read from the output into a string,
so I do
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This hangs at this point.
How should I handle these kind of commands (ping 127.0.0.1) with
| |
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's finished, and if it
is look at its output. I may want to send a signal at some point to
kill the process. This seems straightforward, but it doesn't seem to
be working.
Here's my test case:
|
by: Christian Heimes |
last post by:
Dominique.Holzwarth@ch.delarue.com schrieb:
The pdflatex job stales when the standard stream buffers are full. Why
do you need stdin anyway? The community method should do the trick for you:
out, err = p.communicate()
I also suggest you use the form instead of a single string +
shell=True.
|
by: rdabane |
last post by:
I'm trying to perform following type of operation from inside a python
script.
1. Open an application shell (basically a tcl )
2. Run some commands on that shell and get outputs from each command
3. Close the shell
I could do it using communicate if I concatenate all my commands
( separated by newline ) and read all the output in the end. So
basically I could do following sequence:
1. command1 \n command2 \n command 3 \n
|
by: newlasdjfk |
last post by:
I have read tons of posts but still can't seem to figure it out.
I want to subprocess.Popen() rsync.exe in windows, and print the stdout in python.
This works...
import subprocess, time, os, sys
cmd = "rsync.exe -vaz souce/ dest/"
p = subprocess.Popen(cmd,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |