PDA

View Full Version : SB6: Handle Text File



NewsArchive
01-12-2009, 02:25 AM
Friedrich

I am trying to build a small .BAT file using the Handle Text File script with little
success. Perhaps I am expecting too much.

I initially tried to replace the 1 line in the file, but got a MSC++ BufferOverun
message when the setup was run.

Next I tried to use the CREATE File to clear it out and then the Insert Line to add my
line.

For the batch file name I use a variable and for the text I want in the batch file I
have another variable %MONDAYLINE% that I build from various functions.

However, when the process setup runs it inserts the variable name, and not its
contents.
The %MONDAYLINE% is written into the file.

How can I get the variable content into the file?
The help does say it wants Text, but I was hoping a variable would also work here.


I am doing this to try and overcome what may be another problem in SB6. In trying to
"Add a Scheduled Task" I build a variable with the path to the MS osql.exe to run a
SQL backup process.
But the scheduled task fails to run, because my command and parameters get surrounded
by double quotes, due I guess to spaces detected in the path.

In the Scheduled Task Run field I get
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe -Usa -Ppasswordhere -S
SERVER\SQLEXPRESS"
but I need
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -Usa -Ppasswordhere -S
SERVER\SQLEXPRESS

Hence I am trying to get SB to build me a batch file with the necessary
"Path\osql.exe" params here
line.

Thanks

John Griffiths

NewsArchive
01-12-2009, 02:28 AM
John,

The attached demo project works without any problem here.


[ Initialize Setup ]
! --- Define commonly used constants ---
#include script "Common Definitions.sbi"

Set Variable %MONDAYLINE% to "I am a variable value"

Create Folder "c:\test"
Text File: Create File "c:\test\mybat.bat"
Text File: Insert Line to "c:\test\mybat.bat" -- %MONDAYLINE%
Text File: Insert Line to "c:\test\mybat.bat" -- This is a test



The %MONDAYLINE% variable is set to "I am a variable value"

Then it creates a mybat.bat in c:\test and adds two lines.

The first line is the value of %MONDAYLINE% and the second line is "This is
a Test".

Does this work for you?

Friedrich

NewsArchive
01-12-2009, 02:29 AM
Hi Friedrich

Your example also works fine here. I shall see what might be my problem. In my project
the variable gets written to the file, not the text. Maybe I have some bad characters
or my text line is too long. I will test shortly (Just enjoying my first morning
coffee here) ..and let you know what happens.

John Griffiths

NewsArchive
01-12-2009, 02:29 AM
Hi Friedrich
My Bad.... Too many variables and I was using one not initialized...

Works great when the correct vars are used.

John Griffiths

NewsArchive
01-12-2009, 02:30 AM
BTW, I think that "Application to Run" in "Add/remove Scheduled Task" does
not support command line parameters. That's why it gets surrounded by
double quotes.

I'll see if it is possible to add an additional "Command Line" entry field
to this function.

Friedrich

NewsArchive
01-12-2009, 02:30 AM
Hi Friedrich

Looks like command line params are supported there, as a peek at some others I have do
have parameters.

After SB adds the Sched Task, when I manually surround the drive\path\filename with
double quotes separate from the params it works fine here(Win XP).

So I think a separate Command Line field would work great. It may also need another
field for "Start In:" Hmmm. This has me wondering if I could create a Shortcut
somewhere in the Path and put the .lnk into the Run field.

One other field that may be worth adding is one to turn off the "Run only if Logged
on" checkbox.

Regards

John Griffiths

NewsArchive
01-12-2009, 02:31 AM
Hi Friedrich

follow-up...

I tested and created the shortcut with the appropriate Run, Command line params, and
start in folder.

Then I plugged the .LNK into the Sched Task run field and it all works GREAT!

John Griffiths