Welcome to iraf.net Monday, May 13 2024 @ 09:53 AM GMT
Fenris |
03/12/2007 04:48PM (Read 4859 times)
|
|
|
Status: offline
Registered: 02/14/2007
Posts: 7
|
I'm doing some scripting in IRAF, and would like to read a filename from the standard input (keyboard) into a string variable in order to then perform operations on the file in question. Something like this should work, I thought anyway:[code:1:7a4d5c03c3]string filenameprint('Enter file to process: ')
scanf("%s", filename)print('Processing ', filename, ' now.')[/code:1:7a4d5c03c3]However, the scanf command doesn't pause and allow any input, it just races through to the end of the code and finishes, with the following printed to screen:[quote:7a4d5c03c3]da> cl < bethany.cl
Enter file to process:
Processing now.
da>
[/quote:7a4d5c03c3]I seem to recall the same thing happening when doing some simple C coding on my Windows terminal at home, but I've looked around and as far as I can tell that's the correct form to use scanf in. Also, if I simply declare the variable and type in the same scanf command line at the cl> prompt, it works just fine and I can enter a string value as planned.What am I doing wrong, and/or is there another way to achieve the same goal?Many thanks.
|
|
|
|
fitz |
03/12/2007 04:48PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
When you redirect the input to run the script, you redirect ALL the input, and so the scanf is being answered by the next line of the file. You need to turn this into a procedure script for it to run as expected (see the Script Programmer's Guide, https://iraf.net/irafdocs/script for details) -Mike
|
|
|
|
| |
|
Content generated in: 0.06 seconds |
|