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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:40:31+00:00 2026-05-26T01:40:31+00:00

I want to call a Fortran program from python. I use the Popen statement

  • 0

I want to call a Fortran program from python. I use the Popen statement from subprocess like this:

p = Popen(['./finput'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)

I then want to send some file names to the fortran program. The fortran program reads them from stdin and then opens the files.
If I use something like:

p_stdout = p.communicate(input='file1.dat\nfile2.dat\n')[0]

everything is fine and the fortran program works as expected.
However I want to give the file names as a variable from within the python program.
So if I use

p_stdout = p.communicate(input=file1+'\n'+file2+'\n')[0]

my fortran program can not open the file names. The problem is that the string that fortran reads looks like this

 f i l e 1 . d a t

with a blank character as a first character and some strange character inbetween every correct character. Unfortunately this only shows up if you print every character of the string individually. If you just print the file name with

print*,file1

you get

file1.dat

So my question is, why is python putting in these strange characters into the communication with the child process and, more important, how do I get rid of the?

  • 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-26T01:40:32+00:00Added an answer on May 26, 2026 at 1:40 am

    Sounds like your Fortran might be getting Unicode, are you using Python 3? If so, then construct the string to be passed then use string.encode()

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

Sidebar

Related Questions

I would like to do the following: In a FORTRAN program call myPackageFunction(MPI_User_function) ...shall
I want to call a function from a .NET DLL (coded in C#) from
I want to call a c# function from my javascript function. I have a
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call some RESTful web services from a J2ME client running on
I want to call an ASHX file and pass some query string variables from
I want to call java function from c++ which takes multiple parameters , I
I want to call a rake task from a cron job that stores remote
I want to call ejb from servlet via remote interface. Maybe it is a
I want to call a PHP file that starts like <?php function connection ()

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.