简体   繁体   中英

Split command line to arguments

I need to launch an external Java process. Arguments are formed elsewhere and are passed to me as a single string. I need to find a certain "-D" key and update its value before actually running a process.

Example:

java -Dosgi.framework.extensions="foo bar" "fdf -Dosgi.framework.extensions=bim bom" 

Should become:

java -Dosgi.framework.extensions="bar" "fdf -Dosgi.framework.extensions=bim bom" 

How do I properly tokenize arguments? Obviously splitting by space is not an option. I'd like to use a plugin from Eclipse infrastructure, if possible.

看看这个是一个有助于命令行选项的API。

I ended up using org.eclipse.debug.core.DebugPlugin.parseArguments . Unfortunately is escapes the result and I'm not sure why and how does that affects the final result. Nevertheless it is passing my tests.

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