简体   繁体   English

Python —使用指定的shell执行shell命令

[英]Python — execution shell commands using a designated shells

so I know python can execute shell commands using subprocess.call() 所以我知道python可以使用subprocess.call()执行shell命令

But I normally use tcsh, and I have a .tcshrc that loads a lot of environmental variables to make my shell comfortable. 但是我通常使用tcsh,并且我有一个.tcshrc,它加载了很多环境变量以使我的外壳舒适。

How do I make my subprocess.call() realize that -- execute my commands in tcsh, load my .tcshrc file? 如何使我的subprocess.call()意识到-在tcsh中执行命令,加载.tcshrc文件?

Explicitly invoke tcsh to execute the respective cmds, like this (replace env with your specific cmd arg list: 显式调用tcsh来执行相应的cmd,如下所示(用特定的cmd arg列表替换env

~/> cat tst.py
#!/usr/bin/python -u
import subprocess
subprocess.call(['/usr/bin/tcsh', '-c', 'env'])
~/> ./tst.py | grep ^DISPLAY
DISPLAY=:0
~/> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM