首页 > 解决方案 > 如何在它仍在运行时在反应本机中监听 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>

   );

}

标签: androidreact-nativemobile

解决方案


推荐阅读