I try to call a vim editor with a file on a specific position from within a java process:
Runtime.getRuntime().exec("gvim /etc/fstab '+normal GW'");
Unfortunately that doesn't work. It gives a strange error message from gvim which doesn't help finding the problem ("/etc/fstab" "/etc/fstab" [readonly] 12L, 664C).
The same command directly entered into a terminal works well.
I tried to modify the command:
Runtime.getRuntime().exec("gvim /etc/fstab +normal\ GW");
which also works when entered directly in a terminal. But this gives the exact same behaviour.
What does work ist splitting the command and its parameters into a String[]:
Runtime.getRuntime().exec(new String[]{"gvim", "/etc/fstab" ,"+normal GW"});
What is the reason for this behaviour? How can I call the above mentioned command as a single string from within Java?