Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:16:17+00:00 2026-06-07T21:16:17+00:00

I am trying to write a python script that sends a string to a

  • 0

I am trying to write a python script that sends a string to a program and puts it in the background. On the command line, I can copy and paste the following code and have it successfully do what I want the python program to do:

printf "f\nil\ncs\n1.e-8 100.0 1.e-8\nn\n0.002\nb\n0.05\nz\n2.e-7\nx4\n5.e-7\n\n\nfort.13\nn\nn\n\n" | vpfit95

where: vpfit95 is an alias to an executable program in my PATH.

A few permutations of what I’ve tried (tried one at a time):

import subprocess
vpfitExecutable = 'vpfit95'

String1=r'f\nil\ncs\n1.e-8 100.0 1.e-8\nn\n0.002\nb\n0.05\nz\n2.e-7\nx4\n5.e-7\n\n\nfort.13\nn\nn\n\n'
String2=r"f\nil\ncs\n1.e-8 100.0 1.e-8\nn\n0.002\nb\n0.05\nz\n2.e-7\nx4\n5.e-7\n\n\nfort.13\nn\nn\n\n"
String3="f\nil\ncs\n1.e-8 100.0 1.e-8\nn\n0.002\nb\n0.05\nz\n2.e-7\nx4\n5.e-7\n\n\nfort.13\nn\nn\n\n"

cmd1 = "printf \"" + String1 + "\"" 
cmd2 = "printf \"" + String1 + "\" | " + vpfitExecutable 
cmd3 = "printf \"" + String2 + "\"" 
cmd4 = "printf \"" + String3 + "\"" 

print cmd2

p1 = subprocess.Popen([vpfitExecutable, cmd1])
p2 = subprocess.Popen([cmd2])
p3 = subprocess.Popen([vpfitExecutable, cmd3])
p4 = subprocess.Popen([vpfitExecutable, cmd4])
p4 = subprocess.Popen([vpfitExecutable, String1])
p5 = subprocess.Popen([vpfitExecutable, String2])
p6 = subprocess.Popen([vpfitExecutable, String3])

# check
p7 = subprocess.Popen([vpfitExecutable]) # works.

And all fail (except p7). Some fail with a “Fortran runtime error: End of file” (which is from the vpfit program). Others fail with a Traceback to the subprocess library and “OSError: [Errno 2] No such file or directory”.

Some checks: When I print cmd2 and copy and paste it into the terminal, it works perfectly. When I run p7, it correctly starts running the program as expected, just without the string fed to it. I’m obviously missing something fundamental here, and I just can’t figure out what. Any help appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:16:19+00:00Added an answer on June 7, 2026 at 9:16 pm

    Yes, you are missing something fundamental – pipes are handled by the shell. To do what you want with subprocess, you should run the vpfit95 as a subprocess, and then communicate with it. See section 17.1.4.2 of the docs, replacing a shell pipeline.

    proc = subprocess.Popen([vpfitExecutable], stdin=subprocess.PIPE)
    proc.communicate(input='your string') 
    

    If you need to inspect the stdout and stderr of vpfit, then grab the handles from the output tuple of communicate.

    A dirty alternative is to run your command with shell=True, which spawns it inside a shell and then you can use a pipe in your command, but it is cleaner to “cut out the middleman” and interact with the subprocess directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a Python script that will copy files from one
I'm trying to write a python script which follows the common unix command line
I’m trying to write a python script that sends a query to TweetSentiments.com API.
I'm trying to write a Python script that uses a particular external application belonging
I am trying to write a python script that takes record data like this
I am trying to write a python script that will change my cwd to
I am trying to write a python program that calculates a histogram, given a
I'm trying to write a python script that does the following from within a
I am trying to write a Python script that will access and modify the
I'm trying to write a simple Python script that inserts .odt documents into an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.