【发布时间】:2015-08-31 16:09:38
【问题描述】:
我需要向当前正在执行的程序发出一些命令,并将当前(远程)执行程序的输出转换为脚本中的某个字符串。我目前遇到的问题是我不知道每个命令的输出,因为它可以从用户那里读取,所以输出也会有所不同。
例如
- ./my_program
- print_output_1 [在 my_program 中]
- print_output_2 [在 my_program 中]
- exit [with in my_program]
如果我手动运行命令,终端会得到这样的结果
bash$ ./my_programe
my_program: print_output_1
my_program:first_line_printed_with_unknown_length
my_program: print_output_2
my_program:second_line_printed_with_unknown_length
my_program: exit
bash$
所以我应该在 python 字符串中得到“first_line_printed_with_unknown_length”和“second_line_printed_with_unknown_length”
execute(my_program)
str1 = execute( print_output_1 )
str2 = execute( print_output_2 )
val = execute( exit )
【问题讨论】:
-
您尝试过什么了吗?如果没有,你应该。如果有,结果如何? ..但是是的,你可以使用
Python -
感谢您的回复。请告诉我可以查看的任何包名称。
-
我已经为你添加了答案。它应该让你对如何解决这个问题有一个非常基本的想法。
标签: python automation remote-access