# Parse Program Output With A Batch File

### Question

• This is my code, pretty simple:

key=Text.GetSubText(File.ReadLine(Program.GetArgument(1),15),16,48)
TextWindow.WriteLine(key)

I would run it with an argument being the file path. Now, I want to be able to retrieve the output with a batch file. I though it would be something like:

@echo off
FOR /F %%G IN ('"key.exe C:\test.txt"') DO echo %%G
Pause

It will launch key.exe with the correct file and key.exe will display the text but the batch file will not retrieve it.

Tuesday, May 11, 2010 5:18 AM

• Spegs,

Unfortunately SmallBasic doesn't provide a method for writing into the standard console stream. TextWindow is it's own entity, which is why your example doesn't work.

As Dudeson suggests, the only way to do what you want at present (that I know of) is to write the output to a file, then get your batch file to process that...

key=Text.GetSubText(File.ReadLine(Program.GetArgument(1),15),16,48)
File.WriteContents( "spegs.txt", key )

then your .bat would be something like...

@echo off
key.exe c:\text.txt
FOR /F %%G IN (spegs.txt) DO echo %%G
Pause

or, if you replace c:\text.txt with the batch file parameter value %1, you can call the batch file like this: mybatch.bat c:\text.txt
which would pretty much give you what you're looking for, albeit via a temporary text file (which you could get your .bat to delete before it exits).


• Proposed as answer by Wednesday, May 19, 2010 4:07 PM
• Marked as answer by Saturday, May 22, 2010 7:19 PM
Tuesday, May 11, 2010 10:00 PM

### All replies

• I can't really help you there because I've never really worked with batch.

But I think this isn't possible with Small Basic.. But I can be wrong..

Why don't you try saving that text in a text file with Small Basic? (file.writeline)

It's the only method I can think of..

Live for nothing, OR CODE FOR SOMETHING!
Tuesday, May 11, 2010 5:26 PM
• Spegs,

Unfortunately SmallBasic doesn't provide a method for writing into the standard console stream. TextWindow is it's own entity, which is why your example doesn't work.

As Dudeson suggests, the only way to do what you want at present (that I know of) is to write the output to a file, then get your batch file to process that...

key=Text.GetSubText(File.ReadLine(Program.GetArgument(1),15),16,48)
File.WriteContents( "spegs.txt", key )

then your .bat would be something like...

@echo off
key.exe c:\text.txt
FOR /F %%G IN (spegs.txt) DO echo %%G
Pause

or, if you replace c:\text.txt with the batch file parameter value %1, you can call the batch file like this: mybatch.bat c:\text.txt
which would pretty much give you what you're looking for, albeit via a temporary text file (which you could get your .bat to delete before it exits).


• Proposed as answer by Wednesday, May 19, 2010 4:07 PM
• Marked as answer by Saturday, May 22, 2010 7:19 PM
Tuesday, May 11, 2010 10:00 PM