流程构建器参数 [英] Process Builder Arguments

查看:50
本文介绍了流程构建器参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

final String commands[] =  {"arp", "-n", "|" ,"grep", "98:5d:ad:3d:36:ef", "|", "awk '", "{print $1}", "'"};
ProcessBuilder pb = new ProcessBuilder(commands); 

根据 MA​​C 地址,我想检索 IP.
当我将此命令插入终端(ubuntu 16.04)时,它可以工作.
但是我在JAVA中使用的时候就不行了.

I would like to retrieve the IP, given the MAC ADDRESS.
When I insert this command to the terminal (ubuntu 16.04) it works.
But it doesn't work when I use it in JAVA.

我做错了什么?

它只有在我这样运行时才有效:

It only works when I run it like this:

final String commands[] =  {"arp", "-n"};
ProcessBuilder pb = new ProcessBuilder(commands); 

推荐答案

您需要调用sh"并将您的管道命令传递给该程序.试试:

You need to invoke "sh" and pass to that program your piped command. Try:

ProcessBuilder b = new ProcessBuilder( "/bin/sh", "-c",
               "arp -n | grep 98:5d:ad:3d:36:ef | awk '{print $1}'" );

这篇关于流程构建器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆