Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing cmdline() for empty-string argumemts on posix systems #634

Merged
merged 1 commit into from Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion psutil/_pslinux.py
Expand Up @@ -765,7 +765,7 @@ def cmdline(self):
fname = "/proc/%s/cmdline" % self.pid
kw = dict(encoding=DEFAULT_ENCODING) if PY3 else dict()
with open(fname, "rt", **kw) as f:
return [x for x in f.read().split('\x00') if x]
return [x for x in f.read()[:-1].split('\x00')]

@wrap_exceptions
def terminal(self):
Expand Down
4 changes: 2 additions & 2 deletions test/test_psutil.py
Expand Up @@ -1558,11 +1558,11 @@ def test_prog_w_funky_name(self):
with open(c_file, "w") as f:
f.write("void main() { pause(); }")
subprocess.check_call(["gcc", c_file, "-o", funky_name])
sproc = get_test_subprocess([funky_name, "arg1", "arg2"])
sproc = get_test_subprocess([funky_name, "arg1", "arg2", "", "arg3", ""])
p = psutil.Process(sproc.pid)
self.assertEqual(p.name(), "foo bar )")
self.assertEqual(p.exe(), "/tmp/foo bar )")
self.assertEqual(p.cmdline(), ["/tmp/foo bar )", "arg1", "arg2"])
self.assertEqual(p.cmdline(), ["/tmp/foo bar )", "arg1", "arg2", "", "arg3", ""])

@unittest.skipUnless(POSIX, 'posix only')
def test_uids(self):
Expand Down