python - 使用`time`命令通过shebang运行python脚本
问题描述
我有一个 python 脚本,我希望能够从 bash 运行它。
这通过shebang简单地解决了。
下一步是在 shebang 中实现 time 命令。
我最好但不是完全成功的想法是使用
#!/usr/bin/env -vS bash -c "time /usr/bin/python3 -OO"
遗憾的是,这并没有让 python 解释脚本文件并以交互式 python 会话结束。
输出是
split -S: ‘bash -c "time /usr/bin/python3 -OO"’
into: ‘bash’
& ‘-c’
& ‘time /usr/bin/python3 -OO’
executing: bash
arg[0]= ‘bash’
arg[1]= ‘-c’
arg[2]= ‘time /usr/bin/python3 -OO’
arg[3]= ‘./mypycheck.py’
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
我怎样才能完成这项工作?提前致谢。
解决方案
At the end summing up all helpful details from here, I was able to reach my goal with the following solution.
- Installing
time
utiliy by runningsudo apt install time
- Using the shebang
#!/usr/bin/env -S /usr/bin/time /usr/bin/python3 -OO
And now all is running the way I was looking for.
推荐阅读
- python - 我怎样才能让 80 位浮点数在 numpy 中工作
- audio - 如何使用 Node.js 设置 Stun 服务器
- c++ - 将一个字符串与数组中的另一个字符串进行比较
- thymeleaf - Thymeleaf - 包含来自同一目录的模板(相对路径)
- swift - 在函数声明警告中找不到 Firebase Firestore 参数“selected_port [out]”
- javascript - 如何使用javascript在段落中显示代码
- c - C中的和积
- javascript - 如何从 OAuth facebook nodejs 获得生日?(我可以在终端登录但无法访问)
- excel - 如何通过列的数值定义范围?
- python - 升级到 Grakn 核心和 python API 1.8.1 使几个 Type 方法失败 - 如何修复它?