bash - Java Runtime exec() not working -


i try execute shell command via java this

if (program.isplatformlinux()) {     exec = "/bin/bash -c xdg-open \"" + file.getabsolutepath() + "\"";     exec2 = "xdg-open \"" + file.getabsolutepath() + "\"";     system.out.println(exec); } else {     //other code } runtime.getruntime().exec(exec); runtime.getruntime().exec(exec2); 

but nothing happens @ all. when execute code prints /bin/bash -c xdg-open "/home/user/desktop/file.txt" in console, not open file. have tried call bash first , xdg-open-command, there not change.

what's problem here , how can solve this?

edit: output of calling looks this:

xdg-open "/home/user/desktop/files/einf in a- und b/allg fil/ref.txt" xdg-open: unexpected argument 'in'

but seeems strange me - why command seperatet before in entire path set in quotation marks?

please note don't need xdg-open this. can use java platform-agnostic desktop api:

if(desktop.isdesktopsupported()) {     desktop.open("/path/to/file.txt"); } 

update

if standard approach still gives issues, can pass parameters array since runtime.exec not invoke shell , therefore not support or allow quoting or escaping:

string program; if (program.isplatformlinux()) {     program = "xdg-open"; } else {     program = "something else"; }  runtime.getruntime().exec(new string[]{program, file.getabsolutepath()}); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -