Python subprocess/Popen with a modified environment

前端 未结 8 800
再見小時候
再見小時候 2020-11-22 14:06

I believe that running an external command with a slightly modified environment is a very common case. That\'s how I tend to do it:

import subprocess, os
my_         


        
8条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 14:53

    To temporarily set an environment variable without having to copy the os.envrion object etc, I do this:

    process = subprocess.Popen(['env', 'RSYNC_PASSWORD=foobar', 'rsync', \
    'rsync://username@foobar.com::'], stdout=subprocess.PIPE)
    

提交回复
热议问题