我写了一个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();
}
}以下方式输出&& error
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发布于 2021-08-20 23:09:48
一个更简单的解决方案是只使用java-ngrok (公开地说,我是开发人员),它是ngrok的Java包装器。它为您提供了对API、隧道等一切内容的编程访问。它可以在Maven Central (文档是here)上找到,您可以这样使用它:
final NgrokClient ngrokClient = new NgrokClient.Builder().build();
final CreateTunnel createTunnel = new CreateTunnel.Builder()
.withAddr(8080)
.build();
// Open a HTTP tunnel on port 8080
// <Tunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:8080">
final Tunnel httpTunnel = ngrokClient.connect(createTunnel);javadoc.io上的完整文档。
发布于 2019-11-04 03:36:16
这是不起作用的,因为命令ngrok http <port number>打开一个新的终端作为输出。我也有同样的问题,但在网上搜索后,我发现了这个ngrok命令curl -s localhost:4040/api/tunnels,它返回了一个JSON对象,定义了你想要的所有信息,包括公共url。在ngrok http之后运行此命令,并执行相同的方法,它将会起作用。
https://stackoverflow.com/questions/52575763
复制相似问题