Skip to main content
Topic: STDIN problem with nwc-conv.exe, version 2.1b (Read 23523 times) previous topic - next topic

STDIN problem with nwc-conv.exe, version 2.1b

This problem has been fixed for nwc-conv.exe version 2.1c
I have removed some non-germane threads.

I can't get nwc-conv.exe to accept STDIN when I Exec it from script.

Caution: if you run the code below, break out of it ASAP with CTRL+C.
Otherwise, it will create a huge file in your temp folder (and eventually fill your disk).

Quote from: test.vbs
strCommand = "sort.exe /+2 /R"
With CreateObject("WScript.Shell").Exec(strCommand)
   .StdIn.WriteLine "!NoteWorthyComposer(2.0)"
   .StdIn.WriteLine "|Rest|Dur:Whole"
   .StdIn.WriteLine "!NoteWorthyComposer-End"
   .Stdin.Close
   WScript.Echo .StdOut.ReadAll
End With

strCommand = "nwc-conv.exe NWCTXT INFO"
With CreateObject("WScript.Shell").Exec(strCommand)
   .StdIn.WriteLine "!NoteWorthyComposer(2.0)"
   .StdIn.WriteLine "|Rest|Dur:Whole"
   .StdIn.WriteLine "!NoteWorthyComposer-End"
   .Stdin.Close
   WScript.Echo .StdOut.ReadAll
End With   
If I run the above with CScript, the "sort" works, but it hangs with "nwc-conv", requiring CTRL+C to exit.
Similar results with WScript.
Since sort.exe works, I conclude that there must be a problem with nwc-conv.exe
I'm using WinXP Pro and Windows Script Host Version 5.7
Any help would be appreciated. If someone could get it to work with PHP, that would be helpful.
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #1
Hi Rick,

You are giving nwc-conv a "clip" when it is expecting a "song".  The start and end lines for a song are different from a clip, and a song is expected to first contain song header info followed by one or more pairs of staff header info and its staff clip.  In particular, nwc-conv wants the song header info in your case (to return INFO), and it's "hanging" because it's happily waiting for the song header info (or perhaps even for just the song start line).

I have created various include files and tools for processing entire songs (as opposed to single clips), and would be happy to help you more offline.

Randy

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #2
You are giving nwc-conv a "clip" when it is expecting a "song".
I don't think so. A "clip" would look like this:
Quote
!NoteWorthyComposerClip(2.0,Single)
|Note|Dur:Whole|Pos:0
!NoteWorthyComposerClip-End
Registered user since 1996

 

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #3
Yep, you're right about that.  I saw the "(2.0)" and compared it to my "song" header constant, which doesn't have the version/issue, and assumed you were using a clip header.  But I forgot that my song class adds the version/issue to the constant later, just like the NWC clip class adds it.  My bad.

But I still stand by the issue of the missing song header (along with the missing staff headers).  A song header consists of SongInfo/PgSetup/PgMargins/Font items, and staff headers consist of AddStaff/StaffInstrument/StaffProperties items.  You must give nwc-conv a proper song syntax, with a leading song header, and with every clip prefaced by a staff header.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #4
But I still stand by the issue of the missing song header (along with the missing staff headers).  A song header consists of SongInfo/PgSetup/PgMargins/Font items, and staff headers consist of AddStaff/StaffInstrument/StaffProperties items.  You must give nwc-conv a proper song syntax, with a leading song header, and with every clip prefaced by a staff header.
That is not my experience. This is a perfectly valid nwctxt file:
Quote from: test.nwctxt
!NoteWorthyComposer(2.0)
!NoteWorthyComposer-End
If you save it to a file, you can open it with NWC and/or get its INFO with nwc-conv
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #5
Well strike two for me.  I'm amazed that NWC will allow *all* song header and *all* staff header info to default!  I've had no trouble with running nwc-conv from a PHP script, and I'd assumed it was because I was supplying all the header info.  But it works for me even with no headers whatsoever.  So this must be a VBS-specific issue?

VBS isn't case-significant, is it?  I see one of your StdIn's is Stdin, but it's that way for the sort example too, so that can't be it?  Does writing a blank line after the song footer line help any?  Is VBS something available in Windows by default, or does it have to be installed somehow?  Can't test any theories without it.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #6
Well strike two for me.  I'm amazed that NWC will allow *all* song header and *all* staff header info to default!
It will even work with:
Quote
!NoteWorthyComposer(2!NoteWorthyComposer-End

I've had no trouble with running nwc-conv from a PHP script, and I'd assumed it was because I was supplying all the header info.  But it works for me even with no headers whatsoever.  So this must be a VBS-specific issue?
I have no trouble running nwc-conv from a VBS script, so long as the first parameter is not "NWC" or "NWCTXT".

VBS isn't case-significant, is it? Does writing a blank line after the song footer line help any?
No and no.

Is VBS something available in Windows by default
Yes. wscript.exe and cscript.exe
Or you can get it here:
http://www.microsoft.com/downloads/details.aspx?familyid=47809025-D896-482E-A0D6-524E7E844D81&displaylang=en
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #7
IMO, there is a bug in nwc-conv.exe

If, on the commandline, I type:
Quote
echo x | nwc-conv NWCTXT INFO
a rather large file: nwccnvi1.NWCTXT is created in my temp folder. In looking at the file, it appears that nwc-conv reads the STDIN, and writes it out to the above file, but then continues to write 0xFF to the file until I manually terminate it with CTRL+C. Not nice. A Console program should not do this in response to having data piped to it.
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #8
Ah, now I see the problem.  You are using piping to supply STDIN, whereas I've always used file redirection:

Quote
nwc-conv NWCTXT INFO < xxx.nwctxt

works fine, but:

Quote
type xxx.nwctxt | nwc-conv NWCTXT INFO

fails as you say.  It may be that nwc-conv is watching for an EOF character coming from the stream, when instead (or additionally) it should be checking the FEOF status.  With file redirection, the file is naturally supplying an EOF character (actually even before the end of file usually, due to padding out to a block size).  With piping, the stream sets a status to indicate no more characters available (at that time, as more may come in from the stream subsequently), but does not artificially generate an EOF character.  I think it is typical for GETCHAR to infinitely return hex FF's when the FEOF status is set.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #9
Look's like we agree.
This appears to describe the problem: http://en.wikipedia.org/wiki/C_file_input/output#EOF_pitfall

Quite a PITA for me to code around. I had to write the string out to a file, verify that it is all readable, use Run instead of Exec, and then delete the file.

Thanks for looking at it.
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #10
Looks like I had it backwards - it was checking for FEOF status but not for EOF char.  It's always safest to check for both, and exit if either occurs, to cover all bases.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #11
This is caused by an apparent bug in our compiler's rather old std library. A fix will be available in the next User Tool Starter Kit. In the mean time, it is attached to this reply.

Update on 28-May-2010: NWC-CONV.EXE Version 2.1c can currently be found in the latest beta of the NWC2 User Tool Starter Kit.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #12
Thanks.  Much improved. I can now generate a song file from nwctxt.

I can also generate nwctxt from a song, but only if it is less than 255 bytes. For longer strings, nwc-conv generates an error.
An obscure problem, not worth any more investigation.

What I am trying to do is convert a song to nwctxt and strip out all of the defaults. An example <here>.

This requires that I know what NWC will do if a line is missing or a property is removed.
Ideally, I would like to use: nwc-conv NWCTXT NWCTXT
to convert "stripped" nwctxt to "default" nwctxt. Armed with that knowlege, I can take everything out of nwctxt that is not needed. But that option is not allowed.

Pending further inspiration, it appears that this tool will remain unpublished.
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #13
I can also generate nwctxt from a song, but only if it is less than 255 bytes. For longer strings, nwc-conv generates an error.
An obscure problem, not worth any more investigation.

I do not understand what you are saying here.

Ideally, I would like to use: nwc-conv NWCTXT NWCTXT
to convert "stripped" nwctxt to "default" nwctxt.

I'm not sure why you would want to put effort into something like this, but you can do what you want in two steps, assuming the NWCTXT yields a valid NWC file:

Code: [Select · Download]
nwc-conv NWCTXT NWC | nwc-conv NWC NWCTXT

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #14
If a pipe is used within Exec(), STDOUT cannot be read programatically.

As for the 255 byte limit, if I have string that is the contents of a song file, I can write it to STDIN but I get an error from nwc-conv if the string is longer than 255 bytes. I don't know if it is a script problem or a nwc-conv problem.
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #15
What kind of error? The stdin/out of NWC-CONV has no particular size limits. It seems to work fine with 1.5 MB versions of Tina Billett's 1812 overture saved as NWCTXT.

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #16
After half a day of hacking, I figured it out. The problem is Windows Script Host's ReadAll() function.
It returns a string that it says is the correct length, and for 256 bytes after the first NullChar that it encounters, contains the correct data. But for longer strings, all the data after the first NullChar is garbage. If it always contained garbage, or returned the correct length, I would have understood the problem in a few minutes. Grrr...

The workaround is to use:
Code: [Select · Download]
strSong = .StdOut.Read(&h7FFF)
or for large strings:
Code: [Select · Download]
Do Until .StdOut.AtEndOfStream
  strSong = strSong & .StdOut.Read(&h7FFF)
Loop
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #17
See the attachment
The stdin/out of NWC-CONV has no particular size limits.
It seems to work just fine. If you feed it garbage, it errs (as I would expect).
Registered user since 1996

Re: STDIN problem with nwc-conv.exe, version 2.1b

Reply #18
When receiving piped or redirected input data, NWC-CONV creates a file from it. As you figured out, this error was trying to tell you that the input passed to NWC-CONV was corrupt or invalid.