简体   繁体   English

从程序中捕获执行的命令

[英]Capture executed commands from programs

Is there a way to capture the commands executed by GUI programs ? 有没有办法捕获GUI程序执行的命令? Or even simple bash scripts ? 甚至是简单的bash脚本? Like the "history" command from bash but available on the whole system. 就像bash的“ history”命令一样,但在整个系统上都可用。

A shell (eg bash) has -x option and you can see all the commands which are executed by a particular script. 外壳程序(例如bash)具有-x选项,您可以看到由特定脚本执行的所有命令。 run sh -x <your_script and see the output. 运行sh -x <your_script并查看输出。 You also can temporarily turn on/off this logging by issuing set +x , set -x inside a script. 您还可以通过在脚本内发出set +xset -x来临时打开/关闭此日志记录。

regarding GUI programs, the answer depends on your needs, what kind of activity you'd like to log. 关于GUI程序,答案取决于您的需求以及您想要记录的活动类型。 You can use strace as suggested in the comments, and filter out exec* calls. 您可以按照注释中的建议使用strace ,并过滤掉exec*调用。 But likely you assume something else since most activities of a GUI program are performed w/o executing external programs. 但是您可能会假设其他事情,因为GUI程序的大多数活动都是在不执行外部程序的情况下执行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM