“script python em bash” Respostas de código

Como executar scripts bash em python

import subprocess
print "start"
subprocess.call("sleep.sh")
print "end"
Cooperative Crab

script python em bash

Just pass a HereDoc to python -.

From python help python -h:
-      : program read from stdin

#!/bin/bash
MYSTRING="Do something in bash"
echo $MYSTRING

python - << EOF
myPyString = "Do something on python"
print myPyString

EOF

echo "Back to bash"
DreamCoder

script python em bash

You can use heredoc if you want to keep the source of both bash and python scripts together. For example, say the following are the contents of a file called pyinbash.sh:

#!/bin/bash
echo "Executing a bash statement"
export bashvar=100

cat << EOF > pyscript.py
#!/usr/bin/python
import subprocess

print 'Hello python'
subprocess.call(["echo","$bashvar"])

EOF

chmod 755 pyscript.py

./pyscript.py
Now running the pyinbash.sh will yield:

$ chmod 755 pyinbash.sh
$ ./pyinbash.sh
Exe
DreamCoder

Respostas semelhantes a “script python em bash”

Perguntas semelhantes a “script python em bash”

Mais respostas relacionadas para “script python em bash” em Shell/Bash

Procure respostas de código populares por idioma

Procurar outros idiomas de código