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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:38:57+00:00 2026-06-10T21:38:57+00:00

I am running ghostscript in a subprocess, which is working well except I don’t

  • 0

I am running ghostscript in a subprocess, which is working well except I don’t seem to be able to capture errors.

import subprocess

cmd = 'gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=jpeg -sOutputFile=img-%d.jpeg -r150 -g600x600 sample.pdf'
p = subprocess.Popen(cmd.split(), shell=False, stderr=subprocess.PIPE)

stderr = p.communicate()

print stderr

My problem is whether the command executes correctly or no the stderr always equals:

(None, ”)

I made a second attempt specifying both stdout and stderr

p = subprocess.Popen(slide_cmd.split(), shell=False, stdin=PIPE, stdout=PIPE, stderr=STDOUT)

p.stdout gives output but p.stderr still returns on None

  • 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-10T21:38:59+00:00Added an answer on June 10, 2026 at 9:38 pm

    Ghostscript seems to write mostly to STDOUT, except for the summary of fatal errors like

    GPL Ghostscript 8.71: Unrecoverable error, exit code 1
    

    which ends up on STDERR. So, read STDOUT as well and you should be able to capture everything.

    In order to help debug this, print the command you’re executing in python using subprocess and then use IO redirection in your shell to redirect output to files in order to see on that stream GS outputs what. For example: gs [args] 2>stderr.txt 1>stdout.txt

    On a side note, you should use shlex.split() instead of str.split() to tokenize argument lists, see this note in the subprocess docs.

    On a second site note: Once you start substituting ‘sample.pdf’ with an actual filename using string formatting (cmd % filename), make sure you escape that %d (because it’s meant to be interpreted by GS, not Python) by using %%d instead.

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

Sidebar

Related Questions

I am running a ghostscript command from the shell to convert a postscript file
Running a ServiceHost with a single contract is working fine like this: servicehost =
Running into another issue that I just seem cant to find any information what
I have the latest GPL Ghostscript v9.05 and I am running it on Win
Running Solr on Tomcat 7 on Win 2008 Server. I am looping through a
Running my script through Devel::NYTProf showed that the following portion of code took up
Running Puppet v2.7.14 on CEntOs 6 and also using Apache/Passenger instead of WEBrick. I
Running the following line in my script gives me a Permission denied error: $config_out
Running this program is printing forked! 7 times. Can someone explain how forked! is
Running the following program on gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and Intel(R) Core(TM)2 Duo CPU,

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.