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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:36:16+00:00 2026-05-15T20:36:16+00:00

First let me say that I know it’s better to use the subprocess module,

  • 0

First let me say that I know it’s better to use the subprocess module, but I’m editing other people’s code and I’m trying to make as few changes as possible, which includes avoiding the importing any new modules. So I’d like to stick to the currently-imported modules (os, sys, and paths) if at all possible.

The code is currently (in a file called postfix-to-mailman.py that some of you may be familiar with):

if local in ('postmaster', 'abuse', 'mailer-daemon'):
  os.execv("/usr/sbin/sendmail", ("/usr/sbin/sendmail", 'first@place.com'))
  sys.exit(0)

This works fine (though I think sys.exit(0) might be never be called and thus be unnecessary).

I believe this replaces the current process with a call to /usr/sbin/sendmail passing it the arguments /usr/sbin/sendmail (for argv[0] i.e. itself) and ‘someaddress@someplace.com’, then passes the environment of the current process – including the email message in sys.stdin – to the child process.

What I’d like to do is essentially send another copy of the message before doing this. I can’t use execv again because then execution will stop. So I’ve tried the following:

if local in ('postmaster', 'abuse', 'mailer-daemon'):
  os.spawnv(os.P_WAIT, "/usr/sbin/sendmail", ("/usr/sbin/sendmail", 'other@place.com'))
  os.execv("/usr/sbin/sendmail", ("/usr/sbin/sendmail", 'first@place.com'))
  sys.exit(0)

However, while it sends the message to other@place.com, it never sends it to first@place.com

This surprised me because I thought using spawn would start a child process and then continue execution in the current process when it returns (or without waiting, if P_NOWAIT is used).

Incidentally, I tried os.P_NOWAIT first, but the message I got at other@place.com was empty, so at least when I used P_WAIT the message came through intact. But it still never got sent to first@place.com which is a problem.

I’d rather not use os.system if I can avoid it because I’d rather not go out to a shell environment if it can be avoided (security issues, possible performance? I admit I’m being paranoid here, but if I can avoid os.system I’d still like to).

The only thing I can think of is that the call to os.spawnv is somehow consuming/emptying the contents of sys.stdin, but that doesn’t really make sense either. Ideas?

  • 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-15T20:36:17+00:00Added an answer on May 15, 2026 at 8:36 pm

    While it might not make sense, that does appear to be the case

    import os
    
    os.spawnv(os.P_WAIT,"/usr/bin/wc", ("/usr/bin/wc",))
    os.execv("/usr/bin/wc", ("/usr/bin/wc",))
    
    $ cat j.py | python j.py 
           4       6     106
           0       0       0
    

    In which case you might do something like this

    import os
    import sys
    
    buf = sys.stdin.read()
    wc = os.popen("usr/sbin/sendmail other@place.com","w")
    wc.write(buf)
    wc.close()
    wc = os.popen("usr/sbin/sendmail first@place.com","w")
    wc.write(buf)
    wc.close()
    sys.exit(0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all let me say that I know about dynamic, no PIA, named
First let me say that I really feel directionless on this question. I am
First, let me say that I'm a complete beginner at Python. I've never learned
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},
Let me state first: I know that any user that wants to run a
First of all, let me just say that I'm using the PHP framework Yii,
Hi there First of all just let me say that I'm new in Python
Let's say the first N integers divisible by 3 starting with 9. I'm sure
First of all, let me say I am very new to rails, have been
First, let me use one sentence to let out some frustration: My god, developing

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.