How to use export with Python on Linux

后端 未结 12 1548
梦如初夏
梦如初夏 2020-11-29 23:09

I need to make an export like this in Python :

# export MY_DATA=\"my_export\"

I\'ve tried to do :

# -*- python-mode -*-
# -         


        
12条回答
  •  盖世英雄少女心
    2020-11-29 23:26

    import os
    import shlex
    from subprocess import Popen, PIPE
    
    
    os.environ.update(key=value)
    
    res = Popen(shlex.split("cmd xxx -xxx"), stdin=PIPE, stdout=PIPE, stderr=PIPE,
                env=os.environ, shell=True).communicate('y\ny\ny\n'.encode('utf8'))
    stdout = res[0]
    stderr = res[1]
    
    

提交回复
热议问题