@ Shared server / Environment without pyenv
or ʻanaconda`
ʻGoogling what corresponds to IPC :: Open3`. ↓
subprocess
is recommended.
However,,,
↓
In the Python
2 series, the standard is not used, and it is clearly stated that subprocess32
can be used.
What's that? I wish I could replace it normally.
I don't have root privileges, so use pip
to enter it locally.
Of course, the version of Python
should be 2 series.
python
$ pip install --install-option="--prefix=$HOME/share" subprocess32
#$ export PYTHONPATH=$HOME/share/lib64/python2.6/site-packages:
python
import sys
import platform
py_version = platform.python_version_tuple()[0]
if py_version == 2:
sys.path.append('/home/bunzaemon/share/lib64/python2.6/site-packages')
from subprocess32 import Popen, PIPE
else:
from subprocess import Popen, PIPE
I think it's more like Python
to use try
, but ...
Popen
Popen
--String type in 2 series --Byte type in 3 series
return it. It cannot be handled properly unless it is changed to string [^ 2].
[^ 2]: The script doesn't pass unless decode ("utf-8 ")
is output even though ʻutf-8is not output @
Python2.6.6`
python
cmd = 'ls -al'
p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)
out = ( p.communicate()[0].split("\n") if py_version == 2 else
p.communicate()[0].decode("utf-8").split("\n") )
for line in out:
print (line)
Error in comunicate () [1]
.
You can use it like ʻIPC :: Open3normally, but for the time being, let's get used to the recommended
comunicate`.
python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Importing libraries
import sys
import platform
py_version = platform.python_version_tuple()[0]
if py_version == 2:
sys.path.append('/home/bunzaemon/share/lib64/python2.6/site-packages')
from subprocess32 import Popen, PIPE
else:
from subprocess import Popen, PIPE
cmd = 'ls -al'
p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)
out = ( p.communicate()[0].split("\n") if py_version == 2 else
p.communicate()[0].decode("utf-8").split("\n") )
for line in out:
print (line)
Recommended Posts