我写了一个Java程序,用http 8080运行ngrok。成功执行ngrok.exe后出现跟随错误。如何获取特定输出并在控制台中打印而不是整个输出?
String[] command = {
"src/Ngrok/ngrok.exe",
"src/Ngrok/ngrok.exe http 8080"
};
String line;
Process p;
BufferedReader input = null;
try {
p = Runtime.getRuntime().exec(command);
input = new BufferedReader(
new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
logsStatus.replaceSelection(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != input) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
以下列方式输出&&错误
NAME:
ngrok - tunnel local ports to public URLs and inspect traffic
COMMANDS:
authtoken save authtoken to configuration file
credits prints author and licensing information
http start an HTTP tunnel
start start tunnels by name from the configuration file
tcp start a TCP tunnel
tls start a TLS tunnel
update update ngrok to the latest version
version print the version string
help Shows a list of commands or help for one command
此错误:
ERROR: Unrecognized command: src/Ngrok/ngrok.exe http 8080
这不起作用,因为命令ngrok http <port number>
打开一个新端子作为输出。我遇到了同样的问题,但是在网上搜索后,发现此ngrok
命令curl -s localhost:4040/api/tunnels
返回了JSON
对象,该对象定义了所需的所有信息,包括公共URL。在ngrok
http之后运行此命令,并执行相同的方法即可。