FileOpen Issue

Hey all,

I think I might be losing my brain, but I've been having trouble with fileopen. I wrote this quick little batch file to illustrate. Does anyone else have this issue?

Code:
set h=%@FileOpen["%1",r]
set l=%@FileRead[h]
set r=%@FileClose[h]
If I run it against a text file (I've tried several) I receive:
Code:
TCC: (Sys) C:\Temp\xx.btm [2] The parameter is incorrect.
"%@FileRead[h]"
TCC: (Sys) C:\Temp\xx.btm [3] The handle is invalid.
"%@FileClose[h]"
Any idea what I'm doing wrong? I seems that the handle is not getting set correctly due to the fileclose message. I've also tried to hard code the name to ensure that I wasn't mistyping the command line.

I know I've used fileopen/fileread many times in the past, but I seem to be stuck here.

Thanks,

Michael
 
May 29, 2008
47
0
Orion Arm, MWG
Code:
set h=%@FileOpen["%1",r]
set l=%@FileRead[h]
set r=%@FileClose[h]
I would think that the h argument is being interpreted literally rather than being replaced by the value of h. Try using %h in the second and third SET commands and see if that fixes things.
 
May 20, 2008
3,520
3
Elkridge, MD, USA
frossm wrote:
| Hey all,
|
| I think I might be losing my brain, but I've been having trouble with
| fileopen. I wrote this quick little batch file to illustrate. Does
| anyone else have this issue?
|
|
| Code:
| ---------
| set h=%@FileOpen["%1",r]
| set l=%@FileRead[h]
| set r=%@FileClose[h]
| ---------
|
| If I run it against a text file (I've tried several) I receive:
|
| Code:
| ---------
| TCC: (Sys) C:\Temp\xx.btm [2] The parameter is incorrect.
| "%@FileRead[h]"
| TCC: (Sys) C:\Temp\xx.btm [3] The handle is invalid.
| "%@FileClose[h]"
| ---------
|
| Any idea what I'm doing wrong? I seems that the handle is not getting
| set correctly due to the fileclose message. I've also tried to hard
| code the name to ensure that I wasn't mistyping the command line.
|
| I know I've used fileopen/fileread many times in the past, but I seem
| to be stuck here.

It is a well-known phenomenon (called psychological stet) that we see not
what we actually wrote, but what we thought we wrote. In your 2nd and 3rd
statements you use the letter h, instead of the value of the variable h -
i.e., %h.

I've been victim of this, too!
--
HTH, Steve