- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个运行其他 shell 脚本的 python (v3.3) 脚本。我的 python 脚本还打印诸如“关于运行脚本 X”和“完成运行脚本 X”之类的消息。
当我运行我的脚本时,我得到了 shell 脚本的所有输出,这些输出与我的打印语句分开了。我看到这样的东西:
All of script X's output
All of script Y's output
All of script Z's output
About to run script X
Done running script X
About to run script Y
Done running script Y
About to run script Z
Done running script Z
我运行 shell 脚本的代码如下所示:
print( "running command: " + cmnd )
ret_code = subprocess.call( cmnd, shell=True )
print( "done running command")
我写了一个基本的测试脚本并且做 *没有*看到这种行为。这段代码符合我的预期:
print("calling")
ret_code = subprocess.call("/bin/ls -la", shell=True )
print("back")
知道为什么输出没有交错吗?
最佳答案
谢谢。这可行,但有一个限制 - 在命令完成之前您看不到任何输出。我从另一个使用 popen 的问题 ( here ) 中找到了答案,但也让我可以实时查看输出。这是我最终得到的结果:
import subprocess
import sys
cmd = ['/media/sf_git/test-automation/src/SalesVision/mswm/shell_test.sh', '4', '2']
print('running command: "{0}"'.format(cmd)) # output the command.
# Here, we join the STDERR of the application with the STDOUT of the application.
process = subprocess.Popen(cmd, bufsize=1, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(process.stdout.readline, ''):
line = line.replace('\n', '')
print(line)
sys.stdout.flush()
process.wait() # Wait for the underlying process to complete.
errcode = process.returncode # Harvest its returncode, if needed.
print( 'Script ended with return code of: ' + str(errcode) )
这使用 Popen 并允许我查看被调用脚本的进度。
关于python subprocess.call 输出不交错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20112859/
我有两个列表,保证第一个比第二个多一个项目。我想知道创建一个新列表的最 Pythonic 方法,该列表的偶数索引值来自第一个列表,奇数索引值来自第二个列表。 # example inputs list
我正在尝试构建一个导航,它在显示菜单/导航时错开包含的列表项的外观。 我有一个汉堡符号,单击它时会呈现导航(全屏)。我现在想要一个动画,其中不同的列表项(实际链接)出现时彼此有一些延迟,顶部的是第一个
我想在 jquery 1.3 中为一系列项目制作动画,每个下一个项目在第一个动画的中途开始。换句话说,我想要一个半队列的效果。我尝试使用下面的代码,但它不起作用。有人有什么想法吗? $("h3
我按照这篇文章创建了交错布局。 No good example about RecyclerView and StaggeredGridLayoutManager in Android Docs 当我
我有一个包含数据和类的表,比如 ---------------- | DATA | Class | ---------------- | 1 | A | | 2 | A |
这个问题在这里已经有了答案: Interweaving two numpy arrays (13 个答案) 关闭 4 年前。 我正在尝试如下交错数组。 import numpy as np x =
我想创建两个输出交错的线程,如下所示 Thread1:1=>Ping! Thread2:2=>Pong! Thread1:3=>Ping! Thread1:4=>Ping! Thread2:
这个问题在这里已经有了答案: How to elegantly interleave two lists of uneven length? (9 个回答) How to interleave tw
我试图在 GridView 中显示字符串的动态列表。每个单词都是可点击的,可以选择或取消选择。我附上了 Flipboard 的屏幕截图,因为我想要完全相同的功能。 请帮助我找出要在我的应用中实现的相同
这个问题在这里已经有了答案: Merge two lists (6 个回答) 4年前关闭。 有没有办法可以合并 2 个列表 let a = ["a"; "b"; "c"] let b = ["d";
我正在尝试使用 tf.data.Dataset 来交错两个数据集,但这样做时遇到问题。给出这个简单的例子: ds0 = tf.data.Dataset() ds0 = ds0.range(0, 10,
我有一个元素数组 1 5 9(例如 a1 a2 a3) 第二个元素数组 2 4 8 (e.g. b1 b2 b3) 我希望输出为 1,2 5,4 9,8(即 a1,b1 a2,b2 a3,b3)...
我这里有解决方案代码: // Pre-condition: The fronts of two linked lists are provided. // Post-condition: A link
我有一个矩阵,我想根据下面描述的以下方案按行进行洗牌: 我们有矩阵a: import numpy as np np.random.seed(0) low = -5 high = 5 num_frame
我继承了一些在 Linux 嵌入式平台上运行的 ALSA 代码。现有的实现使用 snd_pcm_readi() 和 snd_pcm_writei() 来阻塞读取和写入。 我的任务是让它在 ARM 处理
我如何将 2 个矩阵 A、B 合并为一个,以便新矩阵 C = A 的第 1 行,然后是 B 的第 1 行,然后是 A 的第 2 行,B 的第 2 行,A 的第 3 行,行B 的 3 等等?最好没有 f
如果我像这样迭代 std::map: typedef std::map clist; clist m_connections; for (const auto itt : m_connections)
我在弄清楚 boost 图像库时遇到了一些问题。 我找不到任何关于如何使用 boost::gil 库中包含的 interleaved_view 函数的确切文档。更具体地说,我不知道原始数据应该以什么二
而不是通过编写创建对象: obj: object [ name: "Fork" id: 1020 ] 我想写一些类似... obj: something-or-another [nam
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:lan
我是一名优秀的程序员,十分优秀!