Page 1 of 1 1
Topic Options
#181083 - 2007-10-03 03:53 PM redirectoutput and blat
booey Offline
Getting the hang of it

Registered: 2005-07-25
Posts: 76
Loc: USA
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.

Top
#181085 - 2007-10-03 04:09 PM Re: redirectoutput and blat [Re: booey]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
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().
Top
#181086 - 2007-10-03 04:14 PM Re: redirectoutput and blat [Re: booey]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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.

Top
#181093 - 2007-10-03 09:10 PM Re: redirectoutput and blat [Re: Richard H.]
booey Offline
Getting the hang of it

Registered: 2005-07-25
Posts: 76
Loc: USA
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.

Top
#181094 - 2007-10-03 09:29 PM Re: redirectoutput and blat [Re: booey]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Do you have the UDF in your code?

Another way is to use the Writeline() function
_________________________
Today is the tomorrow you worried about yesterday.

Top
#181095 - 2007-10-03 09:33 PM Re: redirectoutput and blat [Re: booey]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181096 - 2007-10-03 09:38 PM Re: redirectoutput and blat [Re: Gargoyle]
booey Offline
Getting the hang of it

Registered: 2005-07-25
Posts: 76
Loc: USA
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

Top
#181097 - 2007-10-03 10:02 PM Re: redirectoutput and blat [Re: booey]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
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.

Top
#181098 - 2007-10-03 10:05 PM Re: redirectoutput and blat [Re: NTDOC]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
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)


Edited by Gargoyle (2007-10-03 10:26 PM)
Edit Reason: To fix the $file.name error that I missed
_________________________
Today is the tomorrow you worried about yesterday.

Top
#181100 - 2007-10-03 10:11 PM Re: redirectoutput and blat [Re: Gargoyle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
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-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181102 - 2007-10-03 10:27 PM Re: redirectoutput and blat [Re: Glenn Barnas]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok you are right, quit trying to beat me to 1K \:\) I have fixed my snippet
_________________________
Today is the tomorrow you worried about yesterday.

Top
#181103 - 2007-10-03 10:34 PM Re: redirectoutput and blat [Re: Gargoyle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
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-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181104 - 2007-10-03 10:42 PM Re: redirectoutput and blat [Re: Glenn Barnas]
booey Offline
Getting the hang of it

Registered: 2005-07-25
Posts: 76
Loc: USA
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.

Top
#181105 - 2007-10-03 10:55 PM Re: redirectoutput and blat [Re: booey]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#181107 - 2007-10-03 11:08 PM Re: redirectoutput and blat [Re: Glenn Barnas]
booey Offline
Getting the hang of it

Registered: 2005-07-25
Posts: 76
Loc: USA
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.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 156 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.037 seconds in which 0.011 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org