Why ps output gets truncated when called from script?
Issue
- I am calling
ps
from a script and its output gets truncated on width - How to set windowsize in pexpect module?
[root@]# cat file
#!/usr/bin/python
import pexpect
p=pexpect.spawn('ps -eaf')
p.setwinsize(44,250)
p.expect(pexpect.EOF)
print p.before
p.close()
expected output:
<<>>
[root@]# ps -eaf | grep python
root 2388 1 0 Feb24 ? 00:00:10 /usr/bin/python /usr/sbin/osad --pid-file /var/run/osad.pid
root 15738 13272 0 16:20 pts/4 00:00:00 grep python
root 63794 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/SSL_server.py SSL
root 63803 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/DomainAuthentication.py SSL
root 63812 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/LocalAuthentication.py SSL
root 63821 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/AcL.py SSL
<<>>
after execution script gives following truncated output
[root@]# ./file | grep python
root 2388 1 0 Feb24 ? 00:00:10 /usr/bin/python /usr/sbin/osad -
root 15253 13272 0 15:47 pts/4 00:00:00 /usr/bin/python ./file
root 15254 13272 0 15:47 pts/4 00:00:00 grep python
root 63794 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/Pyt
root 63803 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/Pyt
root 63812 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/Pyt
root 63821 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/Pyt
- After going through
pexpect.py
script , I can see it run thesetwinsize
fuction with default value of 24,80
[root]# cat -n /usr/lib/python2.6/site-packages/pexpect.py | grep setwinsize
535 self.child_fd = sys.stdout.fileno() # used by setwinsize()
536 self.setwinsize(24, 80)
538 # Some platforms do not like setwinsize (Cygwin).
1427 def setwinsize(self, r, c):
1479 p.setwinsize(a[0],a[1])
- I created a local copy of
pexpect.py
script & changed the value from 24,80 to 24,200 & executed the script
output of the script ( as expected )
[root@]# ./file | grep python
root 2388 1 0 Feb24 ? 00:00:10 /usr/bin/python /usr/sbin/osad --pid-file /var/run/osad.pid
root 15285 13272 3 15:49 pts/4 00:00:00 /usr/bin/python ./file
root 15286 13272 0 15:49 pts/4 00:00:00 grep python
root 63794 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/SSL_server.py SSL
root 63803 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/DomainAuthentication.py SSL
root 63812 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/LocalAuthentication.py SSL
root 63821 1 0 Mar05 ? 00:00:00 /usr/bin/python /root/python/PythonGui/AcL.py SSL
Environment
- Red Hat Enterprise Linux 6
- pexpect-2.3-6.el6.noarch
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.