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 7509321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:52:33+00:00 2026-05-29T22:52:33+00:00

I am trying to pass a file to a program (MolPro) that I start

  • 0

I am trying to pass a file to a program (MolPro) that I start as subprocess with Python.

It most commonly takes a file as argument, like this in console:

path/molpro filename.ext

Where filename.ex contains the code to execute. Alternatively a bash script (what I’m trying to do but in Python):

#!/usr/bin/env bash
path/molpro << EOF
    # MolPro code
EOF

I’m trying to do the above in Python. I have tried this:

from subprocess import Popen, STDOUT, PIPE
DEVNULL = open('/dev/null', 'w')  # I'm using Python 2 so I can't use subprocess.DEVNULL
StdinCommand = '''
    MolPro code
'''

# Method 1 (stdout will be a file)
Popen(['path/molpro', StdinCommand], shell = False, stdout = None, stderr = STDOUT, stdin = DEVNULL)
# ERROR: more than 1 input file not allowed

# Method 2
p = Popen(['path/molpro', StdinCommand], shell = False, stdout = None, stderr = STDOUT, stdin = PIPE)
p.communicate(input = StdinCommand)
# ERROR: more than 1 input file not allowed

So I am pretty sure the input doesn’t look enough like a file, but even looking at Python – How do I pass a string into subprocess.Popen (using the stdin argument)? I can’t find what Im doing wrong.

I prefer not to:

  • Write the string to an actual file
  • set shell to True
  • (And I can’t change MolPro code)

Thanks a lot for any help!

Update: if anyone is trying to do the same thing, if you don’t want to wait for the job to finish (as it doesn’t return anything, either way), use p.stdin.write(StdinCommand) instead.

  • 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-05-29T22:52:35+00:00Added an answer on May 29, 2026 at 10:52 pm

    It seems like your second method should work if you remove StdinCommand from the Popen() arguments:

    p = Popen(['/vol/thchem/x86_64-linux/bin/molpro'], shell = False, stdout = None, stderr = STDOUT, stdin = PIPE)
    p.communicate(input = StdinCommand)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass in arguments to the a parent file that is
I'm currently trying to pass a mono threaded program to multithread. This software do
I'm trying to pass one method to another in elisp, and then have that
I'm trying to pass a complex object (that can be serialized, if that helps)
Can I use os.system() or subprocess.call() to execute a Python program on a webserver?
I am trying to create a batch file that removes tel: from a number
this is my first post here! I'm trying to make a windows forms program
I am trying to pass in two .wav files to my program through the
I have a program that passes command-line arguments to an associated file (i.e. associated
I'm trying to local a properties file programmatically without having to pass it's fullpathname

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.