lua中的io.popen函数中的无限循环

时间:2017-12-08 07:06:47

标签: lua popen openwrt

我想无限地执行以下代码。 但是,如果连接了两个设备,则无限循环在第二扫描部分冻结(第二扫描部分意味着无限循环第二次开始并执行扫描命令)。为什么会出现此问题?

while true do
print("Hi")
s = io.popen("iw wlan0 scan")
s:close()
print("Done")

dis = io.popen("iw wlan0 disconnect")
dis:close()

c = io.popen("iw wlan0 connect Name")
c:close()
print("Goes to Scan")
end

此外,如果我手动在命令行中键入命令(扫描 - >断开 - >连接 - >扫描),则扫描打印结果将在第二次扫描时自动重复5到6次。 (当我执行扫描命令时,打印结果为SYNC - 扫描结束,恢复到20MHz通道32,总BSS [02] bImprovedScan .............恢复bImprovedScan,SCAN_PENDING ...... ............此印刷​​文本重复5至6次)。这种情况是否与此问题有关?

1 个答案:

答案 0 :(得分:3)

我不知道public class HttpGetProxy { private static final String PROXY_HOST = "proxy.****.com"; private static final int PROXY_PORT = 6050; public static void main(String[] args) { HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("https://kodejava.org"); HostConfiguration config = client.getHostConfiguration(); config.setProxy(PROXY_HOST, PROXY_PORT); String username = "*****"; String password = "*****"; Credentials credentials = new UsernamePasswordCredentials(username, password); AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT); client.getState().setProxyCredentials(authScope, credentials); try { client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { String response = method.getResponseBodyAsString(); System.out.println("Response = " + response); } } catch (IOException e) { e.printStackTrace(); } finally { method.releaseConnection(); } } } 命令的作用,但是在没有读取任何内容的情况下使用管道并在打开它后立即关闭它会打开程序永远不会执行的可能性。

我建议使用enter code here代替iw

os.execute