简体   繁体   English

Java运行时执行

[英]Java runtime execution

I am trying to execute a docker command from within Java. 我正在尝试从Java内部执行docker命令。 The docker command needs to be executed in the specified directory. docker命令需要在指定目录中执行。

I found this for executing an external command. 我发现这是为了执行外部命令。

public Process exec(String command, String[] envp, File dir) throws IOException

I am unable to understand what exactly does this envp String array is used for? 我不明白这个envp字符串数组到底是envp用的? The documentation reads as: 该文档的内容为:

envp - array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process. envp-字符串数组,其每个元素都具有名称=值格式的环境变量设置,如果子流程应该继承当前流程的环境,则为null。

But I am unable to understand what it exactly means in the documentation. 但是我无法理解文档中的确切含义。 Could someone explain it with an example? 有人可以举例说明吗? What exactly do you need to pass as an argument here. 您究竟需要在此处作为参数传递什么。

Ps: I am using a *nix environment for dev/deployment. 附:我正在使用* nix环境进行开发/部署。

envp - this is an abbreviation, I guess, from env ironment p arameters (or variables). envp -这是一个缩写,我想,从ENV ironment p arameters (或变量)。 For instance it can be path to libraries or something else. 例如,它可以是库或其他东西的路径。

If you do not need specify them, than pass it as null 如果不需要指定它们,则将其传递为null

Runtime.getRuntime().exec(command, null, dir); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM