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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:27:55+00:00 2026-06-17T07:27:55+00:00

This question from years ago does what I need: How do I check out

  • 0

This question from years ago does what I need:

How do I check out a file from perforce in python?

but is there a way to do this using the subprocess module? (which I understand is the preferred way)

I’ve looked through stackoverflow, the python docs, as well as many google searches trying to find a way to use the stdin to send the required input to the p4 process, but I’ve not been successful. I’ve been able to find plenty on capturing the output of a subprocess command, but have not been able to grok the input commands.

I’m pretty new to python in general, so I am likely missing something obvious, but I don’t know what I don’t know in this case.

This is the code I’ve come up with so far:

descr = "this is a test description"
tempIn = tempfile.TemporaryFile()
tempOut = tempfile.TemporaryFile()
p = subprocess.Popen(["p4","change","-i"],stdout=tempOut, stdin=tempIn)
tempIn.write("change: New\n")
tempIn.write("description: " + descr)
tempIn.close()

(out, err) = p.communicate()
print out
  • 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-17T07:27:56+00:00Added an answer on June 17, 2026 at 7:27 am

    As I mentioned in my comment, use the Perforce Python API.

    Regarding your code:

    tempfile.TemporaryFile() isn’t usually appropriate for creating a file and then passing the contents off to something else. The temporary file is automatically deleted as soon as the file is closed. Often you need to close the file for writing before you can re-open it for reading, creating a catch-22 situation. (You can get around this with tempfile.NamedTemporaryFile(delete=False), but that’s still too round-about for this situation.)

    To use communicate(), you need to pass subprocess.PIPE:

    descr = "this is a test description"
    changespec = "change: New\ndescription: " + descr
    
    p = subprocess.Popen(["p4","change","-i"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    
    (out, err) = p.communicate(changespec)
    print out
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I stumbled upon this question from two years ago. Is there a way to
there is a similar question to this from a couple years ago, but I
I got this question from my cousin: What will be the best way to
Why does almost every example I can find (including this question from about a
this is from the 'python cookbook' but isn't explained that well. allchars = string.maketrans('','')
I'm asking this question for posterity reasons and general interest. Years ago I noticed
6-7 years ago i saw an initiative of a way to run python on
I already asked this exact question a year ago. My application uses Python's multiprocessing
I asked this question 6 years ago. In the meantime Android development best practices
When I read this question I remembered someone once telling me (many years ago)

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.