I'm trying to write a script thats spawns a fortran program that needs std file input i.e. you would open it in bash with: ./program < input
How can I do this in python? I have tried the os.spawnl() and it spawns the process but the input does not work.
samush 0 Newbie Poster
Recommended Answers
Jump to PostThere should be a comma after PIPE (I'm guessing that this is a tuple), and then a communicate statement
proc2 = subprocess.Popen("/home/samush/Documents/kandidat_arbete/python/cr_to_fr/fortreaderc", shell=True, stdin = subprocess.PIPE,) proc2.communicate('\tstdin: to stdin\n')
Jump to PostYou should be able to call it with
subprocess.call("./program < " + input_string, shell=True)
Using subprocess to send the input; since you also have a printf, you might have to include an output pipe as well, and you might as well use a stderr pipe which may be more specific …
All 8 Replies
jlm699 320 Veteran Poster
samush 0 Newbie Poster
woooee 814 Nearly a Posting Maven
samush 0 Newbie Poster
samush 0 Newbie Poster
jlm699 320 Veteran Poster
samush 0 Newbie Poster
woooee 814 Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.