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

  • Home
  • SEARCH
  • 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 6003505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:07:51+00:00 2026-05-23T01:07:51+00:00

I want to call up an editor in a python script to solicit input

  • 0

I want to call up an editor in a python script to solicit input from the user, much like crontab e or git commit does.

Here’s a snippet from what I have running so far. (In the future, I might use $EDITOR instead of vim so that folks can customize to their liking.)

tmp_file = '/tmp/up.'+''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
edit_call = [ "vim",tmp_file]
edit = subprocess.Popen(edit_call,stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True )   

My problem is that by using Popen, it seems to keep my i/o with the python script from going into the running copy of vim, and I can’t find a way to just pass the i/o through to vim. I get the following error.

Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

What’s the best way to call a CLI program from python, hand control over to it, and then pass it back once you’re finished with it?

  • 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-23T01:07:52+00:00Added an answer on May 23, 2026 at 1:07 am

    Calling up $EDITOR is easy. I’ve written this kind of code to call up editor:

    import sys, tempfile, os
    from subprocess import call
    
    EDITOR = os.environ.get('EDITOR', 'vim')  # that easy!
    
    initial_message = ''  # if you want to set up the file somehow
    
    with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
      tf.write(initial_message)
      tf.flush()
      call([EDITOR, tf.name])
    
      # do the parsing with `tf` using regular File operations.
      # for instance:
      tf.seek(0)
      edited_message = tf.read()
    

    The good thing here is the libraries handle creating and removing the temporary file.

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

Sidebar

Related Questions

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
If I want to call Bar() instead of Foo() , does Bar() return me
I want to generate Full and Partially Call Trees from cscope database of c
I use tiny_mce as word-like editor in textareas that are in iframes. I want
I want to call a web service, but I won't know the url till
I want to call a few static methods of a CPP class defined in

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.