I have written a program that takes input from STDIN. It works nicely to read a plain text file called test.rpn when I use the following syntaxes...
Code:cat test.rpn | myAppThat's all well and good. However I have read up on "shebang" commands that frequently appear at the top of executable text files (shell scripts and so on). I am now trying to use this technique by making test.rpn executable (chmod +x) and adding a shebang line to the top of that file to use the full path to myApp.Code:myApp < test.rpn
When then run the file (./test.rpn) the shell does indeed invoke myApp but since myApp is expecting the data to be read in from STDIN, it cannot understand and exits without doing anything.
Trouble is that "./myapp test.rpn" is not a valid way to start my app, and that justso happens to be the way that shebang lines pass the filename in.
I've tried all sorts of slight changes to the shebang line to try to get it to "<" redirect the filename into myApp but to no avail.
I also tried adding a second level of shebang by adding a normal shell script in between the test.rpn file and the myApp program. But apparently shebang lines are not able to be nested in this way, it just fails with shell "command not found" errors.
I must have tried about 10 ways to do this but nothing seems to work.
I am very reluctant to make myApp read from a filename in the parameter list because of the already complex logic to process the parameter list. I thought doing the shebang trick would be a neat idea that wouldn't require changes to my binary.
Does anyone have a neat idea about how to achieve this?




Reply With Quote