你如何在Python中执行./executable?

时间:2021-08-10 20:25:58

I have an executable that is a result of compiling and running a C program.

我有一个可执行文件,它是编译和运行C程序的结果。

Let's Call it "file1".

我们称之为“file1”。

Normally, this is how I'd execute it in Linux.

通常,这是我在Linux中执行它的方式。

./file1

But now, I need to execute it from within Python.

但现在,我需要在Python中执行它。

I've tried

os.system("./file1") 

-to no avail. Can someone please help me out?

- 无济于事有人可以帮帮我吗?

P.S - Apologies for the bizzare spacing.

P.S - 为bizzare间距道歉。

1 个解决方案

#1


4  

Use the subprocess module

使用子进程模块

>>> import subprocess
>>> subprocess.call(['./file1'])

#1


4  

Use the subprocess module

使用子进程模块

>>> import subprocess
>>> subprocess.call(['./file1'])