看板Python
标 题Re: [问题] os.system 执行目前目录执行档
发信站SayYA 资讯站 (Tue Sep 30 16:25:01 2008)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ncu!News.Math.NCTU!SayYa
※ 引述《[email protected] (伪ABJ)》之铭言:
> 假设我在目前目录下有一个执行档 a.out
> 如果下 os.system("./a.out")
> 将会出现下列错误讯息:
> sh: ./a.out: not found
请问你目前执行 ./a.out 手动方式可以执行吗 ? 若可以再讨论
python 部分比较好确认问题点. 也许你的 a.out 本来就是无法
被识别可执行项目
> 如果把 ./ 换成绝对路径也不行… @@
> 在前面加 sh 也不行
a.out 不是 shell script, 用这方式肯定是一定不行的.
> 所以如果想执行目前目录底下的执行档该怎麽下才正确呢?
> 话说用 python 来代替 shell script 是不是一个不太好的主意啊?
> 大家觉得勒我是觉得 string 的处理上 loop 等等都比直接写 shell script
> 简单得多
你的问题测试:
$ ls -l
总计 8
-rwxrwxr-x 1 kendlee kendlee 51 2008-09-30 16:20 hello.py*
-rw-rw-r-- 1 kendlee kendlee 70 2008-09-30 16:19 test.c
$ cat -n hello.py
1 #!/usr/bin/python
2
3 import os
4
5 os.system("./a.out")
$ cat -n test.c
1 #include <stdio.h>
2
3 int main()
4 {
5 printf("Hello World from C \n");
6 }
$ gcc test.c
$ ./a.out
Hello World from C
--
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
现代人普遍的现象: 「小学而大遗」、「舍本而逐末」
「以偏而概全」、「因噎而废食」
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
※ Origin: SayYA 资讯站 <bbs.sayya.org>
◆ From: kendlee.sayya.org
1F:推 Reinhard:执行档的确可以执行 这个我确定 09/30 18:02
2F:→ blc:外站来的文章是看不到推文的哦。 09/30 20:12
3F:→ cobrasgo:run a.out和run python时是同一个user吗? 09/30 22:23
4F:推 Reinhard:同一个 user 没错 10/01 06:37