jwalk
jwalk

Reputation: 1147

Running a java class file using unix syntax?

I'm writing a script to validate I/O for contest problem solutions under a given directory for any of the following language types:

I noticed the only one of the three above listed types that cannot be executed in a unix-style syntax ./program < sometest.in is Java. Obviously it's not difficult to simply check file extension in the script and replace above command with format java program < sometest.in, but it made me curious:

Is there a way to use unix-style syntax to run a Java class?

Upvotes: 1

Views: 1740

Answers (1)

Matthias Herlitzius
Matthias Herlitzius

Reputation: 3395

You would need to wrap your Java class / JAR file into a little shell script:

#!/bin/sh

read input
java -jar program.jar $input

Make the file executable:

chmod a+x program

Use it as suggested in your question:

./program < sometest.in

Upvotes: 2

Related Questions