0

I am trying to finish a java program that uploads a file from a client machine to a webserver. The java program is executed with a bat script. I need to pass in a file name to the java program somehow since the filename is different every time. Or can i somehow use %1 instead of the filepath? I dont know.

3 Answers 3

1

Why not simply forward the parameters passed to the shell script to the Java application. I usually do something like this:

#!/bin/zsh

java -jar someapp.jar $@

This will pass all the arguments with which the script was executed to the java app and you can act upon them - as far as I understand you need only only - the file path. I'm not familiar with bat scripts, but I assume they have some similar way of passing args around.

Sign up to request clarification or add additional context in comments.

Comments

1

What does the batch file look like that runs the Java program? You can indeed use parameters like this:

java -jar program.jar %1

If you put that line in a file runprogram.bat, then you could run it with:

runprogram somefilename.xyz

and somefilename.xyz will be passed to the Java program as a command line argument.

Comments

0

No they got it, if i could just pass the filepath as a parameter to the executed jar that would be awesome. Just need to figure out how to pass that parameter into a variable in the program....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.