Page 1 of 2 12>
Topic Options
#145019 - 05/08/08 02:00 PM pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Hi - new to using KiXtart, but been looking at it on and off for a while:

I want to be able to pass a file name and UNC path to the script as a variable $file, archive a copy of the file to an archive folder, and then depending on which directory it can from move it to the relevent remote site. For example, if it came from e:\dropin\london then it goes to the 'London' server, but if it came from the e:\dropin\paris the it goes to the Paris server. I'd like to use a SELECT... CASE startement, but how would I split down the directory? In DOS I can use the variable %~pd1 to pull out the path but how do I do that in KiXtart? I'm no programmer, but can do a little VBS/VB etc. Any assistance greatly appreciated.


Edited by matthewh (05/08/08 02:07 PM)

Top
#145020 - 05/08/08 02:17 PM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Split will split things into an array so that you can pick the bits out of it.

If you only want the very last element, InStrRev() will allow you to look back and find the last "\" in the string - everthing after that is the last element.

For example, to find the last part of a path name:
Code:
$sPath="\\some\path\or\other"
$sLastBit=SubStr($sPath,1+InStrRev($sPath,"\"))
"Last bit of the path is '"+$sLastBit+"'"@CRLF


Top
#145021 - 05/08/08 02:20 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Ok - I'll have a play and let you know. Thanks for that.
Top
#145022 - 05/08/08 02:26 PM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Here is a method using Split(), useful if you need to get other elements of the path:
Code:
$sPath="\\some\path\London\file.txt"
$sPathBits=Split($sPath,"\")
$sFile=$sPathBits[UBound($sPathBits)]
$sCity=$sPathBits[UBound($sPathBits)-1]
"File name is '"+$sFile+"'"+@CRLF
"City name is '"+$sCity+"'"+@CRLF


Top
#145023 - 05/08/08 02:32 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Can I use the variable $file as the string to split? "$file" is used by the application that will call the KiXtart script - I can pass it to a DOS batch file as %1 etc, can I use any variable name in KiXtart or should I use $file?
Top
#145024 - 05/08/08 02:35 PM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
BTW, if you haven't found it already, there are two ways to pass the path to the script.
  1. Set an environment variable and use it directly in the script.
  2. Pass it explicitly on the command line e.g. "kix32.exe $sPath=c:\foo\bar\London\file.txt myscript.kix"

Top
#145025 - 05/08/08 02:41 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Thanks Richard. It's the Explicit one I need but will use $file to pass it to $sPath, i.e.

"kix32.exe $sPath=$file" - if that'll work!

The user manual isn't all that clear to a non-programmer but I'll get there.

Top
#145026 - 05/08/08 02:59 PM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Your application may get confused if it is expanding the variables in the line - you may need to escape the "$" on the "$sPath" to ensure that your app does not expand it.

What is the application that you are using to call the KiXtart script?

Top
#145027 - 05/08/08 03:07 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
It's called YGF, but it doesn't use the variable - it just passes it TO whatever it calls - so that could be another app, or a batch file or in this case a script. I don't need to use it at all. It scans a set of folders every 60 seconds and performs functions of whatever it finds - mostly sends emails, but will do more. I could write a different batch file for each folder but wanted to simplify it and have it call one script. I don't even know if it'll work.
Top
#145028 - 05/08/10 03:18 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
OK - I've been pulling my hair out with this now for a while. Tried VBS - n'good. Tried Robocopy in a batch file, - reads the %1 variable with a trailing "\" after the file name (and if I break it doen with %~pd etc it still fails) so that's no use. Back to KiXtart. I now have a different way of looking at it:

Copy $file "c:\ftp Archive\"

Select

Case Instr($file, "Peterborough")
COPY $file \\xxx.xxx.xxx.xxx\DropIn\Peterborough\

Case Instr($file, "Portsmouth")
copy $file \\xxx.xxx.xxx.xxx\DropIn\Portsmouth\

Case Instr($file, "Sunderland")
copy $file \\xxx.xxx.xxx.xxx\DropIn\Sunderland\

Case Instr($file, "Hartlepool")
copy $file \\xxx.xxx.xxx.xxx\DropIn\Hartlepool\

Case Instr($file, "FTP_TEST")
copy $file \\xxx.xxx.xxx.xxx\DropIn\


EndSelect

It's called from a batch file - runkix.bat and contains the line:

kix32.exe $file=%1 c:\scripts\Filecopy.kix.

I've tried kix32.exe $file=^%1 c:\scripts\Filecopy.kix but that fails.

The conf file for YGF contains the line:

LaunchApplication=Runkix.bat $file

And $file is where the path and filename is stored and it is this I have to pass to the KiXtart script. Tried calling the script direct from the conf file but it don't work.

Any ideas anyone?

Top
#145029 - 05/08/10 04:12 PM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
You have spaces in the path name.

In your batch file, try:
Code:
kix32.exe $file="%1" c:\scripts\Filecopy.kix



Add some diagnostics in the script so you can see what is going on. You can use RedirectOutput() to write the output to a file if the task runs under a service.

Top
#145030 - 05/08/10 04:17 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
I put those spaces in cos it didn't work without anyway, but hadn't tried with "" - doing it now.
Top
#145031 - 05/08/10 05:07 PM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Nope. Still no joy - is there anything on Win2003 Server that might cause problems? Any lockdowns and so on? I've checked all the permissions, the batch/kix files run fine if I run them manually, just not if they are called by YGF. Kinda frustrating really. Just going to try it on W2000 Server.

Edited by matthewh (05/08/10 05:08 PM)

Top
#145032 - 05/08/10 07:30 PM Re: pass file and path as a variable to the script
Witto Offline
MM club member
*****

Registered: 04/09/29
Posts: 1828
Loc: Belgium
Maybe you can write a script that also verifies if files were copied to the source folders?
Code:

Break On
Dim $arrPlaces[], $strPlace, $strFilename
$arrPlaces = "London", "Paris"
While @ERROR = 0
For Each $strPlace in $arrPlaces
$strFilename = Dir("e:\dropin\" + $strPlace)
While $strFilename <> "" AND @ERROR = 0
If $strFilename <> "." AND $strFilename <> ".."
If Exist("\\" + $strPlace + "\Rest\Of\ThePath" + "\" + $strFilename)
Del "\\" + $strPlace + "\Rest\Of\ThePath" + "\" + $strFilename
EndIf
Move "e:\dropin\" + $strPlace + "\" + $strFilename "\\" + $strPlace + "\Rest\Of\ThePath"
EndIf
$strFilename = Dir()
Loop
Next
Sleep 60
Loop


Top
#145033 - 05/08/10 10:46 PM Re: pass file and path as a variable to the script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 01/06/05
Posts: 22294
Loc: Claremore, OK
your code looks fine.
more than fine.
I like tab alignment.

k, just add some:
if @error beep "Error on Del: " @error " - " @serror ? sleep 2 endif

kinda line right after the del.
_________________________
!

download KiXnet

Top
#145034 - 05/08/11 10:34 AM Re: pass file and path as a variable to the script
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
That's great, but you are missing the point.

The (current) problem is that the batch/script is not getting executed.

It needs some debug code added to both to confirm that they are actually being called at all, and what the parameter is if appropriate.

Personally I'd dump YGF, code the new file detection in KiXtart and run it as a scheduled task.

Top
#145035 - 05/08/11 10:58 AM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
Unfortunately - can't dump YGF, as it does other stuff as well. I'm convinced it's Windows 2003 Server - I ran it on my test W2k server her and it worked fine. (Hate to say it but if it was on Unix I'd have had it done last Friday)
Top
#145036 - 05/08/11 11:08 AM Re: pass file and path as a variable to the script
Witto Offline
MM club member
*****

Registered: 04/09/29
Posts: 1828
Loc: Belgium
What is %1?
Can you put something like:
Code:

ECHO %1
PAUSE
kix32.exe $file="%1" c:\scripts\Filecopy.kix


in your batch file?

Top
#145037 - 05/08/11 11:13 AM Re: pass file and path as a variable to the script
matthewh Offline
Fresh Scripter

Registered: 05/08/08
Posts: 10
Loc: Peterborough, UK
if I run the script and send the output to a text file it's fine. It's all where it should be, and I found out late last night running Sysinternal's TCPView that it seems to open a connetion to my test server there to copy the files then sits in a TIME_WAIT, but if I run it manually or on my Windows 2000 server I get ESTABLISHED on the connection. There's a handy open window here that it might fit through......
Top
#145038 - 05/08/11 01:17 PM Re: pass file and path as a variable to the script
Witto Offline
MM club member
*****

Registered: 04/09/29
Posts: 1828
Loc: Belgium
Can you maybe give some example of what YGF is returning and is being used as %1 in your batch file. Just trying to get a better understanding of your problem.
Top
Page 1 of 2 12>


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

Who's Online
1 registered (green78) and 144 anonymous users online.
Newest Members
Keris2112, Jorromans, qrstuv140696, Bloodboy, NIJAKIX
17451 Registered Users

Generated in 0.095 seconds in which 0.041 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