如何解决bash:运行一次命令,然后将stdout和stderr保存在自己的变量中
我需要确保命令输出正确的文本。我目前有:
command_stdout="$(mycommand --flag 2>/dev/null)"
command_stderr="$(mycommand --flag 2>&1 1>/dev/null)"
我不必运行两次相同的命令,有什么办法可以运行一次,但仍然可以将stdout和stderr的输出保存到适当的变量中?
解决方法
将stderr重定向到文件,然后将第二个变量设置为文件内容。
#!/usr/bin/env python3
import kivy
from kivy.uix.modalview import ModalView
from kivy.lang import Builder
from kivy.app import App
KV = """
BoxLayout:
ModalView:
size_hint: 0.9,None
BoxLayout:
orientation: 'vertical'
Label:
text: 'Dialog Title'
font_size: 30
Label:
text: "Lorem ipsum dolor sit amet,consectetur adipiscing elit."
Label:
text: "Lorem ipsum dolor sit amet,consectetur adipiscing elit."
StackLayout:
orientation: 'rl-tb'
Button:
text: "OK"
size_hint: None,None
size: self.texture_size
padding: '8dp','8dp'
Button:
text: "Cancel"
size_hint: None,'8dp'
"""
class MyApp(App):
def build(self):
return Builder.load_string( KV )
MyApp().run()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。