diff --git a/luigi/lock.py b/luigi/lock.py index d26a82c517..1b31ed0c90 100644 --- a/luigi/lock.py +++ b/luigi/lock.py @@ -37,7 +37,7 @@ def getpcmd(pid): """ if os.name == "nt": # Use wmic command instead of ps on Windows. - cmd = 'wmic path win32_process where ProcessID=%s get Commandline' % (pid, ) + cmd = 'wmic path win32_process where ProcessID=%s get Commandline 2> nul' % (pid, ) with os.popen(cmd, 'r') as p: lines = [line for line in p.readlines() if line.strip("\r\n ") != ""] if lines: diff --git a/test/lock_test.py b/test/lock_test.py index 54930a1ca1..7ef8761cc1 100644 --- a/test/lock_test.py +++ b/test/lock_test.py @@ -31,11 +31,18 @@ class TestCmd(unittest.TestCase): def test_getpcmd(self): - p = subprocess.Popen(["sleep", "1"]) + if os.name == 'nt': + command = ["ping", "1.1.1.1", "-w", "1000"] + else: + command = ["sleep", "1"] + + external_process = subprocess.Popen(command) + result = luigi.lock.getpcmd(external_process.pid) + self.assertTrue( - luigi.lock.getpcmd(p.pid) in ["sleep 1", '[sleep]'] + result.strip() in ["sleep 1", '[sleep]', 'ping 1.1.1.1 -w 1000'] ) - p.kill() + external_process.kill() class LockTest(unittest.TestCase):