android - 如何在它仍在运行时在反应本机中监听 shell 命令输出?
问题描述
所以我想听诸如wget
每次进程在运行时打印一些输出时重新渲染
我正在使用react-native-android-shell
,代码是这样的
AndroidShell.executeCommand(command, (result) => {
console.warn("result iz ", result)
});
但我没有得到输出,只是空白字符串,我不知道操作系统是否支持该命令,但我假设库在进程完成之前没有返回输出,想法是每次打印过程时我都想听
期待
const Component = () => {
const [output,setOutput] = useState("");
useEffect(() => {
AndroidShell.listen("some command",(stdout) => {
//re-render every output while it's running
setOutput(stdout);
});
},[]);
return(
<View>
<Text>{output}</Text>
</View>
);
}
解决方案
推荐阅读
- firefox - SVG 文本路径渲染在 Firefox 中出现反转
- c# - 如何在不等待内部方法完成的情况下立即返回“ok”
- java - RecyclerView 搜索过滤器在过滤结果后位置错误
- vscode-remote - 如何在 Windows 中通过 git bash 连接 vscode-remote-ssh 扩展?
- python - 在linux上安装pandas,只用一个python文件
- python - 如何使用文件名(如果提供)或标准输入(如果未提供 argparse)
- ios - UISearchBar 不会更改 iOS 12.1 的搜索图标和占位符颜色
- c++ - 如何重载流运算符以使用位于不同文件中的函数?
- python - 比较两个字符(在字符串内)如何在 Python 中工作
- flutter - 在 DropdownButton 中选择项目时出现断言错误