Page 1 of 1 1
Topic Options
#207891 - 2013-10-08 10:47 PM looking to better understand the results I'm getting
Tsguy Offline
Getting the hang of it

Registered: 2010-01-18
Posts: 67
Loc: Oregon
Hello all,

I'm in the process of writing an administrative kix script for setting up and scheduling defragmentation of specific files / folders for our admin team. My intent / goal with it is a script that will provide a prompt for which paths are to be defragmented and then a number of actions take place.

I'm not going to get into all the moving parts I'm planning, but the relatively simple parts of it are something I'm having some problems with.

Here is the code i'm currently struggling with:

 Code:
? "Enter paths to de-fragmented, separated by commas: "
Gets $PathInput
$PathInput = split($PathInput,",")
;
$Contig="C:\psscripts\contig\contig.exe -s"
$DefragCustomLog="C:\psscripts\contig\defraglog.txt"
;
;
For Each $Path in $PathInput
	? $Path
Next
;
For Each $Path in $PathInput
	shell "%ComSpec% /c $Contig $Path>>$DefragCustomLog"
Next


The above code will not work when a path with spaces is entered. Specifically, paths like C:\program files, won't work when typed in UNLESS they are put in quotes "C:\program files" or in non-8dot3 format (C:\progra~1).

I can work around that, but would love to know if there's someway I can code around it :).

I also am curious what can be done about the data entry prompt. At the prompt to enter paths, as soon as you reach the end of the dos line . . your characters start over-writing each other and it's really hard to know what's being typed. Is there possibly another way that I can leverage a prompt for users to be entering path data that would be easier for data entry?

thoughts and feedback appreicated,

Lan

Top
#207892 - 2013-10-09 12:24 AM Re: looking to better understand the results I'm getting [Re: Tsguy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Lan,

Three points - First, you're better to use semicolons to delimit paths, as it's already a common method in the PATH statement. It pays to be consistent.

Second, you'd be better served to build the shell command in $Cmd, then run Shell $Cmd. This way, even for simple commands, you can dissect it and print it before you run it.

Third, use single quotes for Kix strings. DOS likes double quotes, and using single quotes in Kix allows you to easily embed double quotes in your commands that you Shell or Run.

So, try tyis:
 Code:
For Each $Path in $PathInput
  $Cmd = '%COMSPEC% /c '       ; note trailing space!
  $Cmd = $Cmd + $Contig + ' "' + $Path + '">>DefragCustomLog'
  'About to run:' @CRLF $Cmd @CRLF
  Shell $Cmd
This way, you see the command before you run it - you can verify that the path is properly surrounded with double quotes. When things work as desired, you can comment-out or remove the debug message (or - wrap it in an If $DEBUG command).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207893 - 2013-10-09 12:30 AM Re: looking to better understand the results I'm getting [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Part 2 - two things to do:

1. use $Rc = SetOption('WrapAtEOL', 'On') in your scripts. I use 4 SetOptions in EVERY script I write - WrapAtEOL, Explicit, NoVarsInStrings, and NoMacrosInStrings.

2. Change your input to begin at the left margin:
 Code:
'Input stuff here:' @CRLF
Gets $Input @CRLF
The trailing CRLF insures the messages that follow start on a fresh line.

If you need more than 80 chars and don't want to deal with line wrap, you can use KixForms to pop up a dialog box that will display longer lines or wrap as needed. Downside is that you need to copy kixforms.dll to the workstation and register it for this to work.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207897 - 2013-10-09 12:59 AM Re: looking to better understand the results I'm getting [Re: Glenn Barnas]
Tsguy Offline
Getting the hang of it

Registered: 2010-01-18
Posts: 67
Loc: Oregon
As always Glenn, you are a fount of kix knowledge ;\)

I'm trying several kix actions that are new to me on this one, so the advice is appreciated.

Will see what I can work up regarding the suggestions and will repost code in a bit.

Lan

Top
#207915 - 2013-10-15 04:55 AM Re: looking to better understand the results I'm getting [Re: Tsguy]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
He is a fountain of KiX knowledge so use him while you can because his fountain of youth if filling up fast \:D
Top
Page 1 of 1 1


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

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.057 seconds in which 0.027 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