2

I have an application that reads a text file.

If the application reads it from stdin, then I could forward the input / pipe it

$ app < input.txt
$ cat input.txt | app

Unfortunately, the application expects a filename as an argument..

$ app --input input.txt

and I can't easily change the source of input (eg. swap local file [as in example] for a result of a wget).

Is there an option to somehow trick this app?

If a solution requires a temporary file, it is necessary that this file is not left on the FS..

The app is actually an executable JAR; I'd like the trick to run on Win/Lin..

2 Answers 2

3

I am not sure if it could work for you, but I have already solve a similar problem with a fifo. http://linux.die.net/man/3/mkfifo

This could give you the indirection between your app and your source.

mkfifo fifo.input
app --input fifo.input

Now you can fill the pipe with different sources.

cat input > fifo.input
ctrl-c
cat otherInput > fifo.unput

Hope it solve your problem on Linux. So far I know it does not exist on Windows.

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

4 Comments

this is very nice! Will the fifo.input disappear after reading by app?
No but it take 0 space, the kernel redirect the output to the process directly, no disk space is used. The name on the disk is only an entry point.
this is very good, if you can pinpoint a way to automatically dispose of whatever is created during this operation (even the hd entry), I can accept right away.
If you can launch all your operations in a script it is simple, just remove the fifo at the end of the script : rm fifo.input
0

You want to do something like this.

 java -jar myjar.jar arg1 arg2

where myjar.jar is the executable jar and arg1 arg2 etc are parameters the program expects.

So suppose you want to pass input.txt to your application and its the only commandline parameter required then command will be

java -jar myjar.jar input.txt

4 Comments

How exactly does this read from stdin !? This does not answer the OP's question.
The OP's want to change the source of input without creating the file at defualt location with defualt name. if the application uses sdin as input then he had thought of solution as frowarding the input or pipeing. but as he mentions its a executable jar and he was looking for giving the input without creating extra/temp file.
suppose I don't want to pass an existing file (input.txt), but an online resource (like a webpage's html)
@RoaySpol have you tried creating script with wget to get html save it as temp file pass it to App as commandline parameter and then delete temp generaed file. a small .sh Linux or .bat windows should serve the perpose.

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.