Skip to main content
Topic: VBScript User Tools cause NWC2 to leave temporary files. (Read 4368 times) previous topic - next topic

VBScript User Tools cause NWC2 to leave temporary files.

This does not seem to be a problem with WinXP

Under Win98SE, any time a User Tool is run, NWC2 creates 3 files in windows\temp in the form of nwt*.TMP.  They are the STDIN, STDOUT, and STDERR.  Usually these are deleted when the User Tool finishes, but if the tool "spawns" any processes, they are locked until the spawned process finishes and are never deleted. Here's a simple example:

'---- begin ToNotePad.vbs ---------------
Option Explicit
Dim fso: fso = CreateObject("Scripting.FileSystemObject")
Dim f: f = fso.GetBaseName(fso.GetTempName) & ".txt"
f = fso.BuildPath(fso.GetSpecialFolder(2), f) ' 2 = %TEMP%
fso.CreateTextFile(f).Write(WScript.StdIn.Read(46080))
CreateObject("WScript.Shell").Run(f) ' leaves %TEMP%\nwt*.TMP
WScript.Sleep 500: fso.DeleteFile(f)
If WScript.StdIn.AtEndOfStream Then WScript.Quit
MsgBox "Truncated to 45K bytes", vbExclamation, "Warning"
'---- end ToNotePad.vbs ---------------

The offending line is:
CreateObject("WScript.Shell").Run(f)
which runs notepad and loads the file. The temp files are locked until notepad is closed and never deleted.

I can't figure out how to avoid it. I can solve it with an onExit routine that deletes all the files it can that match the pattern, but if it can be fixed within NWC2, that would certainly be preferable.

I know nothing of PHP (and since I have failed at every attempt to become adept at "regular expressions", I'm not eager to learn.)

Can PHP "spawn processes"? (It may be called "exec" or "shell".)  If so, does it leave the temp files?
Anyone have any ideas on the best way to handle this?
Registered user since 1996

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #1
>I can't figure out how to avoid it.

The only way to avoid problems like this is not to spawn any processes/applications that cause the NWC2 temporary files to be locked.

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #2
I am curious, what are you trying to do? If you just want to show text, it might be better to output the text to STDOUT or STDERROR and allow NWC2 to display it.

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #3
Re: #1
Patient: It hurts when I do this.
Doctor:  well, stop doing it.

I'm not sure what is locking files. That's why I asked about PHP.
Spawning is a large part of scripting. Would be a shame to have it limited.

Re: #2
stdout and stderr display are not much use as they lock the program. If I just wanted to see it, I'd use the Clipboard viewer.

This was as short an example as I had. Some uses:

If I have a measure of music that does not sound right, I highlight it and send it to notepad.  It's like seeing all the properties at once.

Some music is quite repetitive. I put that in notepad, sometimes with comments, and copy/paste from there. Much faster than jumping around the song file.

I have longer scripts. One uses IrfanView to send the current page to the default printer, another sends all pages to a mult-page tif.
Registered user since 1996

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #4
Talking of spawning processes – is there any way of launching an htm or hta file from VBScript and getting a return value (possibly through a temp file if it can't be done directly)?

This would enable some serious user menu possibilities!

One feature (or lack thereof) in the user tools is a 'context'. That is, it would be very useful to know the clef, key and time signature of the selection. Is there any possibility of this being included in the first line of StdIn?

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #5
Sorry, my example had an error. Should have started:

'---- begin ToNotePad.vbs ---------------
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

-----------------------------------------
To Peter:
You can run hta's and html's directly as a user tool.
html probably would not have enough access to do more than display some help.

To get the context you want, you would have to mark the part you wanted the tool to work on (perhaps with some distinctive text) and the send the entire staff.

VBScript will let you access the registry and and the clipboard, something I suspect cannot be done with PHP.
Registered user since 1996

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #6
Rick, what is the precise command for running, say, 'Test.htm'. I just get command process failed.

Your comments on context serve to highlight the problem, but don't really solve i!! I don't want the user to have to go through those steps, when it should be possible to include the context in StdIn

Re: VBScript User Tools cause NWC2 to leave temporary files.

Reply #7
Re: https://forum.noteworthycomposer.com/?topic=5191.msg33205#msg33205  You seem to be right. I can't get an html file to load.

Under XP and Win98 I can get a text file to display with a command: notepad foo.txt but ...
[path]\iexplore foo.htm just hangs NWC2. Once I terminate NWC2 with the task manager (aka Ctrl+Alt+Del->End Task), the web page displays.

Under Win98 I can use start foo.txt, or start Scripts\foo.vbs but start foo.htm hangs NWC2 as above.
Under XP, start seems always to display STDERR with "command process failed". There are a lot of new switches with XP's start command, maybe I need one or more of them.

I thought this may be a memory issue, but with Win98, start foo.pdf works and, in my experience, Acrobat is at least as big a memory hog as IExplore.

All attempts to use VBScript's Run command gave the same result as start. There are some other ways to load web pages with VBScript, so a solution may yet exist.
Registered user since 1996