473,807 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enter parameters into Fortran executable from python cgi script

I have a fortran executable which when run from cmd it asks for a
series of parameters which you enter then hit enter.
From my python cgi script i want to be able to run the executable.
Enter the 4 or 5 parameters needed then end the executable and
redirect to another web page which will display some results given
from an output file from the fortran executable.

When the user clicks submit on the form it seems to hang up on the
interaction between python cgi and fortran exe. In this example the
fortran exe only accepts on variable then terminates.

How do i do this correctly?
testrun3 can be accesed from any dir because it's directory is set in
the environment variables.

import os
os.system("test run3")
os.system("Y")
os.system("exit ")
Jul 18 '05 #1
3 3985
>>>>> "lamar" == lamar air <la*******@hotm ail.com> writes:
lamar> How do i do this correctly? testrun3 can be accesed from
lamar> any dir because it's directory is set in the environment
lamar> variables.

If you want to interact with a program, you need to use popen2 or
popen3, which give you access to the stdin, stdout and stderr
(popen3).

See this thread for a similar discussion and working example:

http://www.google.com/groups?hl=en&l...3D20%26hl%3Den
Note, you could also expose the fortran functions to python directly
with f2py. It is really very easy and automated

http://cens.ioc.ee/projects/f2py2e/
John Hunter

Jul 18 '05 #2
On 11 Jul 2003 07:34:51 -0700, la*******@hotma il.com (lamar_air) wrote:
I have a fortran executable which when run from cmd it asks for a
series of parameters which you enter then hit enter.
From my python cgi script i want to be able to run the executable.
Enter the 4 or 5 parameters needed then end the executable and
redirect to another web page which will display some results given
from an output file from the fortran executable.

When the user clicks submit on the form it seems to hang up on the
interaction between python cgi and fortran exe. In this example the
fortran exe only accepts on variable then terminates.

How do i do this correctly?
testrun3 can be accesed from any dir because it's directory is set in
the environment variables.

import os
os.system("tes trun3")
os.system("Y ")
os.system("exi t")


Using p2test.py in the role of testrun3, which I assume expects a "Y" input
and later an "exit" input (we'll talk about whether you need \n later below),
here is an example using os.popen2 to feed input to child via chin.write and
get output via chout.read:

====< p2test.py >============== =============
import sys
first_inp = sys.stdin.readl ine()
print 'first input was:',`first_in p`
print >>sys.stderr, 'Dummy error message'
second_inp = sys.stdin.readl ine()
print 'second input was:',`second_i np`
1/0 # sure to make exception
=============== =============== ==============

Interactively:
import os
chin,chout,cher r = os.popen3(r'pyt hon c:\pywk\clp\p2t est.py')
chin.write('Y\n exit\n')
chin.close()
print chout.read() first input was: 'Y\n'
second input was: 'exit\n'
print cherr.read()

Dummy error message
Traceback (most recent call last):
File "c:\pywk\clp\p2 test.py", line 7, in ?
1/0 # sure to make exception
ZeroDivisionErr or: integer division or modulo by zero

There can be deadlock situations, which you can read about at

http://www.python.org/doc/current/li...w-control.html

but you don't have a lot of data going to the child process, and you are not
having a continuing interchange with it, so there shouldn't be a problem.

As a first attempt, I'd just substitute 'testrun3' for r'python c:\pywk\clp\p2t est.py'
in the above and see what you get.

If it doesn't work, you can experiment by removing the \n after the Y and/or the exit,
in case testrun3 is calling some single-character low level input for Y (like getch() in C).

HTH

Regards,
Bengt Richter
Jul 18 '05 #3
lamar_air fed this fish to the penguins on Friday 11 July 2003 07:34 am:

You've had other answers already, but I didn't see an explanation of
why your logic didn't work (not for me, for you).

How do i do this correctly?
testrun3 can be accesed from any dir because it's directory is set in
the environment variables.

import os
os.system("test run3")
os.system("Y")
os.system("exit ")
EACH os.system() call is the equivalent of entering a new command at
the CLI/shell level. There is no linkage from one os.system() call to
the next. Therefore, all application input has to be supplied to the
single invocation.

How difficult would it be to modify the Fortran to read command-line
arguments:

testrun3 Y exit
?

Otherwise, as has been shown by others, you'll need something like
popen2 to create a linkage so you can write the arguments to the
application's stdin.

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1136
by: Mathieu Drapeau | last post by:
Hi, I would like to do something like below but I lost my arguments passed via an html web page when I reload python within my script: /import os,sys dirName = "/opt/oracle/product/9.2.0/lib" paths = os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep) if dirName not in paths: paths.insert(0, dirName) os.environ = os.pathsep.join(paths)
1
2381
by: Kumbale, Murali T. | last post by:
I am new to Python and redirection etc. I created a simple COM object in Visual FORTRAN called "disp.disp" that writes to the WINDOWS console. I wrote a Python script which looks like the following import win32com.client o = win32com.client.Dispatch("disp.disp") o.SimpeAdd(5) SimpleAdd method takes the argument supplied (the number 5 in this case) and adds 10 to it and then writes to FORTRAN standard output using
4
4732
by: Torsten Mohr | last post by:
Hi, i'd like to build an executable file that is linked with a python library and executes a script via PyRun_SimpleString or similar functions. Is there a static library of python available, so the users don't need to install python?
15
2112
by: Nick Coghlan | last post by:
Thought some folks here might find this one interesting. No great revelations, just a fairly sensible piece on writing readable code :) The whole article: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=1 The section specifically on white space: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=3 Cheers,
3
5825
by: Holger (David) Wagner | last post by:
Hi all, we're currently developing an application in the .NET environment that needs to access a DLL implemented in Fortran. There is one procedure with about 17 parameters, most of them arrays. After some trial and error experiments, we've found out that a) the parameters must be ordered by type, i.e. we cannot mix double, integers and Strings (char-Arrays) - instead, we first need to put all the float-Arrays and Int32-Arrays, and...
5
1517
by: Christoph Haas | last post by:
Hi, list... I wondered if it's possible to use global (module) variables as default parameters. A simple working example: ---------------------------------------- #!/usr/bin/python globalvar = 123
3
5174
by: unexpected | last post by:
Hi all, I'm currently working on a large, legacy Fortran application. I would like to start new development in Python (as it is mainly I/O related). In order to do so, however, the whole project needs to be able to compile in Fortran. I'm aware of resources like the F2Py Interface generator, but this only lets me access the Fortran modules I need in Python. I'm wondering if there's a way to generate the .o files from Python (maybe...
3
2121
by: sam | last post by:
hello all, i am currently in the process of planning a piece of software to model polymerisation kinetics, and intend to use python for all the high-level stuff. the number-crunching is something i would prefer to do in fortran (which i have never used, but will learn), but i have no experience of accessing non-python code from python. i am also fairly new to programming period, and am therefore tackling a fairly serious issue reletive...
10
8362
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's NumPy manual, I have a quick question (hopefully) regarding how to read in Fortran written data. The data files are not binary, but ASCII text files with no formatting and mixed data types (strings, integers,...
0
9599
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,...
0
10626
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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,...
0
10112
tracyyun
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...
0
9193
agi2029
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...
1
7650
isladogs
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...
0
5546
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...
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.