简体   繁体   English

如何运行 python 脚本来测试我自己的 shell?

[英]How do I run a python script to test my own shell?

I am making my own shell and I want to make a python script to automate tests.我正在制作自己的 shell,我想制作一个 python 脚本来自动化测试。 I would like to run both programs like this: ./my_shell | test.py我想像这样运行这两个程序: ./my_shell | test.py ./my_shell | test.py

How can I do that ?我怎样才能做到这一点 ?

import os


def command(command):
    exit_status = os.system(
        "echo \"%s\" | ./42sh > output 2> errout" % command)
    with open("output", "r") as output_file:
        output = output_file.read()
    with open("errout", "r") as error_file:
        error = error_file.read()
    return output, error, exit_status / 256


out, err, ex = command("ls -a")

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

相关问题 如何从elisp运行我自己的shell? - How can I run my own shell from elisp? 在python中,如何让我自己的异常类在shell中打印出来? - In python, how do I get my own exception classes to be pretty printed in the shell? 如何为我的 python 脚本创建自动化测试? - How do I create an automated test for my python script? 如何为我的 Python 脚本生成测试数据? - How do I generate test data for my Python script? 如何将python脚本作为shell脚本运行? - how do you run a python script as a shell script? 如何使用 libpython-clj 将我自己的 python.py 文件集成到我的 Clojure 脚本中? - How do I integrate my own python .py file into my Clojure script using libpython-clj? 如何将我的 shell 扫描脚本嵌入到 Python 脚本中? - How do I embed my shell scanning-script into a Python script? 如何获取 python 脚本以在 Windows (10) 中运行命令 shell (10),它在程序特定位置打开? - How do I get a python script to run a command shell in Windows (10) where it opens in a program specific location? Python:我如何阅读(不运行)shell 脚本,沿途插入 arguments - Python: how do I read (not run) a shell script, inserting arguments along the way 如何在 ec2 实例的用户数据中运行我自己的 shell 脚本 - How to run my own shell script inside user data in ec2 instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM