booey
(Getting the hang of it)
2007-10-03 03:53 PM
redirectoutput and blat

Hi everyone. I am trying to create a script that will get a list of all filenames in a directory, output that list to a file and then send it with blat. I can create the file fine, but when I try to send it with blat, I get the error: "unknown error code 32 when trying to open C:\temp\kix\kixtest.txt" Here is my code so far.

 Code:
BREAK ON
DIM $faildir,$faildirplus,$body,$file

$faildir ="\\server\share\folder\"
$faildirplus = dirplus($faildir,"/a-d /f tif")

For Each $file In $faildirplus
		If RedirectOutput("C:\temp\kix\kixtest.txt",0) = 0
		? $file.name
		;@SERROR
	Else
EndIf
Next
Sleep 1

Shell '\\server\netlogon\Programs\blat.exe C:\temp\kix\kixtest.txt -t recipient@domain.com -f sender@domain.com -server mailhost.com -subject "Test"'



Also, I'm using redirectoutput to create the file because I couldn't figure out how to get each filename to populate in the file using writeline. If writeline is the better method, please let me know.

Does anyone have any idea why I'm getting the error when trying to send? It seems like the file might still be in use.

Thanks.


eriqjaffe
(Hey THIS is FUN)
2007-10-03 04:09 PM
Re: redirectoutput and blat

I usually use the WriteFile() UDF to pump an array out to a text file, myself. I find it to be a bit cleaner than RedirectOutput() or WriteLine().

Richard H.Administrator
(KiX Supporter)
2007-10-03 04:14 PM
Re: redirectoutput and blat

The problem is that you still have the file open (exclusively) so Blat cannot open it for reading.

Try including a $=RedirectOutput("") to close the file before you Blat it.


booey
(Getting the hang of it)
2007-10-03 09:10 PM
Re: redirectoutput and blat

Thanks for the input. I'm trying to use the writefile function, but I can't get the array to write to the file. It creates the file ok, but it's blank. Can you tell me what I am doing wrong?

 Code:
BREAK ON
DIM $faildir,$faildirplus,$body,$file,$wf,$wfstrip

$faildir ="\\server\share\folder\"
$faildirplus = dirplus($faildir,"/a-d /f tif")
For Each $file In $faildirplus
	$wfstrip = stripsuffix($file.name)
? $wfstrip

Writefile("C:\temp\kix\test.txt",$wfstrip)	
	
Next


When I output the $wfstrip to the screen, it shows me the filenames that I'm looking for, but they don't get put in the file. I'm sure it's something easy, but not for me apparently.

Thanks.


Gargoyle
(MM club member)
2007-10-03 09:29 PM
Re: redirectoutput and blat

Do you have the UDF in your code?

Another way is to use the Writeline() function


Glenn BarnasAdministrator
(KiX Supporter)
2007-10-03 09:33 PM
Re: redirectoutput and blat

Since you aren't sending an array to WriteFile, I'm not sure it will really work (without digging into your code more deeply).

Also - what's up with "$File.Name" ? ? ?

I use RedirectOutput for almost all output since it's so foolproof. You do need to close the redirection before you call Blat, as Richard said earlier.

To debug, add some print statements and see what it's doing along the way.

Finally, here's some simple logic, once you've got the $FailDirPlus array from DirPlus, that will create the file for Blat to use.

 Code:
$ = RedirectOutput('BlatMessage.txt')
For Each $File in $FailDirPlus
  $File ?
Next
$ = RedirectOutput('')
$BlatCmd = 'blat.exe blah ' + $some_Var + ' more blat args...'
'BlatCmd is ' $BlatCmd ?
Shell $BlatCmd
@SERROR ?


Glenn


booey
(Getting the hang of it)
2007-10-03 09:38 PM
Re: redirectoutput and blat

Yes, the UDF is in my code.

I tried using writeline initially, but only the first filename in the array was being written to the file.
Here is my code when using writeline
 Code:
$faildir ="\\server\share\folder\"
$faildirplus = dirplus($faildir,"/a-d /f tif")
For Each $file In $faildirplus
	If Open(3,"C:\temp\kix\test.txt",5) = 0
		WriteLine(3,$file.name)
		Else
			EndIf
Next


NTDOCAdministrator
(KiX Master)
2007-10-03 10:02 PM
Re: redirectoutput and blat

Well you need a CRLF after each line otherwise it will keep overwriting the same line.

Then you also need to close the file before moving on.


Gargoyle
(MM club member)
2007-10-03 10:05 PM
Re: redirectoutput and blat

Rewrite you code like this...

 Code:
$faildir ="\\server\share\folder\"
$faildirplus = dirplus($faildir,"/a-d /f tif")
If Open(3,"C:\temp\kix\test.txt",5) = 0
  For Each $file In $faildirplus
    WriteLine(3,$file + @CRLF)
  Next
EndIf
Close(3)


Glenn BarnasAdministrator
(KiX Supporter)
2007-10-03 10:11 PM
Re: redirectoutput and blat

How many kix koders will it take to convice Booey to CLOSE his output stream?? \:o

Once again, if DirPlus returns an array, and that array is called "$FailDirPlus", and you enumerate the array using a var called "$File" (as in FOR EACH $FILE IN $FAILDIRPLUS), how does anyone expect a reference to $File.Name to work in that loop? We're enumerating an array of values, not an array of objects, right?

G-


Gargoyle
(MM club member)
2007-10-03 10:27 PM
Re: redirectoutput and blat

Ok you are right, quit trying to beat me to 1K \:\) I have fixed my snippet

Glenn BarnasAdministrator
(KiX Supporter)
2007-10-03 10:34 PM
Re: redirectoutput and blat

Well, it's just that you, Richard, Eriqjaffe (indirectly) and I all mentioned closing the output stream, and every example he posted neglected to close it.

I'm still scratching my head about the .Name thing.. ;\)

G-


booey
(Getting the hang of it)
2007-10-03 10:42 PM
Re: redirectoutput and blat

Hey, I never said I was good at scripting... \:\) I didn't see your reply when I replied back to the writeline response.

The $file.name returns just the filename, whereas $file returns the whole path. I don't want the whole path, just the filename. I'm using file.name in my script now and it works just fine.


Glenn BarnasAdministrator
(KiX Supporter)
2007-10-03 10:55 PM
Re: redirectoutput and blat

OK - I stand corrected.. I was looking at (an apparently very old) copy of DirPlus in my local function library. Looking at the one posted on KORG, I see it returns an array of FSO objects, so the ".Name" now makes sense.

Also not trying to comment on your scripting skills - considering you're confident enough to be using UDFs and be enumerating arrays and all. Was trying to make light of the "CLOSE THE DAMN FILE" issue. ;\)

BTW - don't ask how many kix koders it takes to change a light bulb (lamp) - it's already a UDF.

One more suggestion, though - put the "?" after your print, not before. It's a shortcut for @CRLF - a "line termination", not a line initiator. It's not a shortcut for "print" like in some dialects of BASIC. With the "?" in front, the first line of your file is empty, and some apps won't like that. Don't have a copy of Blat handy to check here at work.

Glenn


booey
(Getting the hang of it)
2007-10-03 11:08 PM
Re: redirectoutput and blat

Thanks for the suggestions. I'll start doing that with the "?".

I do appreciate everyone's help though. This board is a lifesaver and is very helpful for people like me.