2021-10-15 02:36:49 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
class SubprocessTest(unittest.TestCase):
|
|
|
|
def test_execve(self):
|
|
|
|
tmp_dir = tempfile.mkdtemp()
|
|
|
|
self.addCleanup(shutil.rmtree, tmp_dir)
|
2024-03-03 00:57:56 +00:00
|
|
|
exe = os.path.join(tmp_dir, 'hello')
|
|
|
|
shutil.copyfile('/zip/.python/test/hello', exe)
|
2021-10-15 02:36:49 +00:00
|
|
|
os.chmod(exe, 0755)
|
|
|
|
proc = subprocess.Popen([exe], stdout=subprocess.PIPE)
|
|
|
|
stdout, stderr = proc.communicate()
|
|
|
|
self.assertEqual(b'hello world\n', stdout)
|
|
|
|
self.assertEqual(0, proc.wait())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|