How to determine if a procedure was passed a file to standard input when run via the command line

DOKTORF

New Member
Hello. By running the procedure through the command line, pointing it to the input file like this
Code:
_progres -b -p test.p < test.txt
I can read the contents of test.txt into test.p with a simple
Code:
 def var cline as c no-undo.
_tt:
do while true on endkey undo _tt,leave _tt:
import unformatted cline.
end.
However, if i don't pass a file to test.p, then without an explicitly open input, the error will be ** Attempt to read with no current source of input. (513). How to determine that a procedure was passed a file as input.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
It sounds like you want to conditionally read the contents of a file. But I'm not sure, as you are stating your chosen solution rather than the problem you are trying to solve.

I didn't know this type of input was possible for an OpenEdge client. It's an interesting curiosity but I wouldn't use it.

Rather than trying to use input redirection, why not define an input stream? You can look for the existence of a known file and, if it exists and is readable, input from the file and import its contents.

This input stream solution will also make it much more obvious to a future maintainer what the procedure is intended to do, without having to know the command line required to make it work. They won't read the code and wonder, "where the heck is the input coming from?"

Also, it looks to me like your solution will only be practical (or even possible?) from a starting procedure, whereas you can use an input stream in any procedure.
 

DOKTORF

New Member
This is how new processes are created in the processing queue, and the initial parameters of the work are often transferred in files. This was long before me, and I understand that it would be much more convenient to send parameters via -param, but it's done as it's done. I just want to protect programs from errors during execution if there is no input file
 

Stefan

Well-Known Member
I tried all sorts, but am unable to catch the error.
I tried seek( input ) - but the redirected input is special and returns unknown value.
I tried fetching the command line with a Windows API call, but this returns the command line without the redirected input file.
I tried using GetStreamHandle - and just failed.

So while I completely agree with Rob that this is archaic stuff - I am curious if anyone tackles this.
 

TomBascom

Curmudgeon
I needed this a while back for much the same reasons that the original poster did. That part about stdin being -10 wasted an afternoon of my life :rolleyes:
 
Top