0

Currently I am trying to create a desktop application using Swing's file chooser that will convert a specific type of file to another one, making use of cygwin. The relevant code part is :

String[] cmd = new String[]{"C:\\cygwin64\\bin\\mintty.exe", "/cygdrive/c/Users/orhun.vatansever/workspace/extchangegui/src/extchangegui/dene.sh"};
                Process pr = Runtime.getRuntime().exec(cmd);

which is working fine, but since the content of my bashscript is like

cd "${0%/*}"
java -jar xyz.jar aegis.xyz

This means my code is working for one specific xyz file, what I want to do is select the file and run the command on that specific xyz file. I can get the filename with myfile.getName(), however I don't know how to use this data, where to put it in process builder. I see two solutions I think, one is setting one of the process builder parameters(don't know which one) to "java -jar xyz.jar "+file.getName()"" , other is changing the script's content upon clicking the open button of file chooser(which doesn't make sense I think).

Morbidity
  • 93
  • 3
  • 11

1 Answers1

0

You can add the name string to your command array and reference it as a positional parameter in your script. Say cmd[2] = "xyz",

 java -jar ${2}.jar aegis.${2}

That's not what I want to do…I want to…get its name via file.getName() property, and somehow pass it to the script, or run it like java -jar xyz.jar + chosenFile.getName()

Then pass the file name in the command string, cmd[2] = file.getName(),

 java -jar xyz.jar ${2}

You should also consider using ProcessBuilder to create your Process.

Community
  • 1
  • 1
Catalina Island
  • 7,027
  • 2
  • 23
  • 42
  • that's not what I want to do,what I want to do is being able to pass the chosen file and get its name via file.getName() property, and somehow pass it to the script, or run it like "java -jar xyz.jar "+chosenFile.getName()"" , – Morbidity Mar 24 '17 at 10:55
  • but isn't file a java object and getName() a java property, are they preserved when I run them in my script? – Morbidity Mar 24 '17 at 11:58
  • I tried what you said, it did not return any error however it also did not generate the folder as it should – Morbidity Mar 24 '17 at 12:01
  • Add `echo ${2}` to your script to see what's coming through. – Catalina Island Mar 27 '17 at 10:28