简体   繁体   中英

Setting project folder as standard when using command line in Java?

I am using a provided python script in a project which I call using

Process p=Runtime.getRuntime().exec("cmd /c cd C:\\Users\\Kevski\\Desktop\\EKI Projekt\\Route Planning\\tools\\ && python draw.py coordinates.route");

It creates an image from the coordinates.route file which I later use again in Java. It also works fine - on my computer. My question is can I automatically let the path above be adjusted to the project folder so that it works on any machine?

Thanks very much in advance!

This is what Properties are for. You could define the path in a property file and read it and then use it in the command. As a simple example, you cold pass the path from java command line (if running from command line) or in web/app server configuration file for -D parameter. When in command line, send path as a parameter as :

java -Dpath.to.command="/usr/local/" YourClassName

In the class, the property can be read as :

String path = System.getProperty("path.to.command");

If path is not null, construct the complete command using variable path and proceed. Thus you have externalized the path, and then can be passed from command line in any environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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