【问题标题】:how to programmatically(python) execute terminal commands after invoking shell script(control will be under shell script))调用shell脚本后如何以编程方式(python)执行终端命令(控制将在shell脚本下))
【发布时间】:2017-05-01 04:34:32
【问题描述】:

操作系统:Ubuntu 16.04LTS。 Python 自动化。

嗨,我正在尝试在 ubuntu 中进行 python 自动化,我必须以编程方式调用 shell 脚本,在调用 shell 脚本后我需要输入并执行终端命令。

我正在使用以下命令调用 shell 脚本

import os
os.system("gnome-terminal --working-directory='/home/murlee/CTS/android-cts/tools' -e 'bash -c \"./cts-tradefed; exec bash\"'")

*现在我需要帮助才能在调用 shell 脚本后输入和执行终端命令

调用 shell 脚本后,我的终端将如下所示 Terminal_snapshot

"murlee@murlee-Lenovo-ideapad-100-14IBD:~/CTS/android-cts/tools$ ./cts-tradefed

Android CTS 6.0_r17 版本:3866870

cts-tf >(这里我要输入命令并执行)"

谢谢!

【问题讨论】:

    标签: python shell terminal ubuntu-16.04


    【解决方案1】:

    创建一个名为my-init.sh的初始化脚本

    ./cts-tradefed
    

    现在打电话

    import os
    wd  = '/home/murlee/CTS/android-cts/tools'
    cmd = "bash --init-file {0}".format('./my-init.sh')
    os.system("gnome-terminal --working-directory='{0}' -e '{1}'").format(wd,cmd)
    

    【讨论】:

    • 你能告诉我一些关于 my-init.sh 的细节吗?我试过你的回答,但我不知道在哪里保存 my-init.sh 文件。请检查我的错误和 my-init.sh 命令。 #!/bin/bash $SCRIPT_PATH="/home/murali/CTS /android-cts/tools/cts-tradefed.sh" exec "$SCRIPT_PATH", 错误:- 为该终端创建子进程时出错,未能执行子进程“{1}”(没有这样的文件或目录)。
    猜你喜欢
    • 2017-01-15
    • 1970-01-01
    • 2021-05-08
    • 2019-11-21
    • 2018-02-27
    • 1970-01-01
    • 2011-05-21
    • 2014-12-18
    • 1970-01-01
    相关资源
    最近更新 更多