Source language: Translate to:

FileRead errors

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

FileRead errors

Postby dpayer » Fri Jul 31, 2009 9:49 am

I am experiencing a problem with a simple function and would appreciate any insight people would have. In my project I create text files from command line apps. I want to read them and parse them in NB. When I do, I only get odd characters or empty lines.

The text file can be opened in notepad (via NB after having created the file) with no problem. In fact I can do so right before I attempt to read the file in NB which it then fails!

Code: Select all
FileExists "[pubdir]installedprinters.txt" "[iplistexists]"
           If "[iplistexists]" "=" "False"
           AlertBox "Problem" "Installed Printers file does not exist"
           Else
               FileLen "[pubdir]installedprinters.txt" "[linesINinstprn]"
               Delay "500"
               Loop "1" "[linesINinstprn]" "[whereinloopIPL]"
                    FileRead "[pubdir]installedprinters.txt" "[whereinloopIPL]" "[preIPL]"
                    Delay "200"
                    Alertbox "test" "read from installed printers|line#:[whereinloopIPL]|value:[preIPL]"
Endif


I have attempted to delay the process to make sure the file is written and the batch file that created it is closed. I set the run command to wait until the process is finished before continuing and this step happens after that run command.

It is an odd problem. I am doing another fileread in the app prior to this without any issues.

Is my logic wrong? The txt file appears normal with normal ascii codes in it (normal spaces are used and CR LF ends each line). The alertbox from this displays odd ascii characters or empty lines but I get an alertbox for each and every loop made.

Here is the batch file used to create the text file:
Code: Select all
rundll32 printui.dll,PrintUIEntry /ge /c\\%computername% /f installedprinters.txt


Here is a simple version of installedprinters.txt:
Code: Select all
Printer Name: \\David4\201
Server Name: \\David4



I appreciate any insight.

David P.
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Neosoft Support » Fri Jul 31, 2009 10:21 am

When I try your code, I receive the following error message:

"Unable to enumerate per machine printer connections..."

The output file "installedprinters.txt" is created but contains only gibberish - the same when read from NeoBook or viewed in Notepad.

This error is probably specific to my PC configuration, but I noticed that your batch file didn't contain a path for the output file. What might be happening is that the output file is being written somewhere other than you expect and that NeoBook is reading an older version of the file.

Below is the code I used for my test:

Code: Select all
Run "rundll32.exe" "printui.dll,PrintUIEntry /ge /c\\%computername% /f [#34][PubDir]installedprinters.txt[#34]" "Wait" "" ""

FileExists "[pubdir]installedprinters.txt" "[iplistexists]"
If "[iplistexists]" "=" "False"
  AlertBox "Problem" "Installed Printers file does not exist"
Else
  FileLen "[pubdir]installedprinters.txt" "[linesINinstprn]"
  Delay "500"
  Loop "1" "[linesINinstprn]" "[whereinloopIPL]"
    FileRead "[pubdir]installedprinters.txt" "[whereinloopIPL]" "[preIPL]"
    Delay "200"
    Alertbox "test" "read from installed printers|line#:[whereinloopIPL]|value:[preIPL]"
  EndLoop
Endif


I used NeoBook's Run action instead of a batch file so I could use the "Wait" option which insures that the utility finishes before I attempt to open the file. I also added a missing "EndLoop" to the code. The FileRead action reads the output exactly as created by the utility.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby dpayer » Fri Jul 31, 2009 11:23 am

Neosoft Support wrote:When I try your code, I receive the following error message:

"Unable to enumerate per machine printer connections..."

The output file "installedprinters.txt" is created but contains only gibberish - the same when read from NeoBook or viewed in Notepad.

This error is probably specific to my PC configuration, but I noticed that your batch file didn't contain a path for the output file. What might be happening is that the output file is being written somewhere other than you expect and that NeoBook is reading an older version of the file.

Below is the code I used for my test:

Code: Select all
Run "rundll32.exe" "printui.dll,PrintUIEntry /ge /c\\%computername% /f [#34][PubDir]installedprinters.txt[#34]" "Wait" "" ""

FileExists "[pubdir]installedprinters.txt" "[iplistexists]"
If "[iplistexists]" "=" "False"
  AlertBox "Problem" "Installed Printers file does not exist"
Else
  FileLen "[pubdir]installedprinters.txt" "[linesINinstprn]"
  Delay "500"
  Loop "1" "[linesINinstprn]" "[whereinloopIPL]"
    FileRead "[pubdir]installedprinters.txt" "[whereinloopIPL]" "[preIPL]"
    Delay "200"
    Alertbox "test" "read from installed printers|line#:[whereinloopIPL]|value:[preIPL]"
  EndLoop
Endif


I used NeoBook's Run action instead of a batch file so I could use the "Wait" option which insures that the utility finishes before I attempt to open the file. I also added a missing "EndLoop" to the code. The FileRead action reads the output exactly as created by the utility.



Thanks for looking. The rest of my code did have an endloop.

I realize now that this method of generating a list will only work if you are using a print server. It does not display locally installed printers and if you have no server shared printers it may not do anything but it does appear to create a file with some characters in it and this may be the problem (unreadable characters in the txt file).

I will have to find another way to do this. I think the file generated is actually part of the problem. RE: path using [pubdir] when using a batchfile (I prefer .cmd files as you don't have to run the command prompt first) it places the file in the same directory as the .cmd file.

I can get this info via the registry as well but it seems the get registry functions in both native NB and 3rd party (MattLib) do not get what I want.

I will write something in the "suggestions" area for expanded registry reading ability.

Again, thanks for looking.

David P.
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Neosoft Support » Mon Aug 03, 2009 9:59 pm

NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest