Page 1 of 1 1
Topic Options
#36830 - 2003-02-22 06:53 AM How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
I havent been able to figure out or find info on opening a separate dos window for each command that I want to execute. I want to run a bunch of tail comands, each in it's own window. Can someone please help.
Top
#36831 - 2003-02-22 07:11 AM Re: How to run a separate CMD window for each command
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
use the start command

quote:
G:\>start /?
Starts a separate window to run a specified program or command.

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program]
[parameters]

"title" Title to display in window title bar.
path Starting directory
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application
I The new environment will be the original environment passed
to the cmd.exe and not the current environment.
MIN Start window minimized
MAX Start window maximized
SEPARATE Start 16-bit Windows program in separate memory space
SHARED Start 16-bit Windows program in shared memory space
LOW Start application in the IDLE priority class
NORMAL Start application in the NORMAL priority class
HIGH Start application in the HIGH priority class
REALTIME Start application in the REALTIME priority class
ABOVENORMAL Start application in the ABOVENORMAL priority class
BELOWNORMAL Start application in the BELOWNORMAL priority class
WAIT Start application and wait for it to terminate
command/program
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.

If it is not an internal cmd command or batch file then
it is a program and will run as either a windowed application
or a console application.

parameters These are the parameters passed to the command/program

If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.

Press any key to continue . . .


Top
#36832 - 2003-02-22 07:55 AM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
Can you run multiple commands with the start command? For example:

tail -f something | grep something

Top
#36833 - 2003-02-22 08:18 AM Re: How to run a separate CMD window for each command
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Most things (within reason) that you can normally do from a command prompt can be shelled out and done as well from KiXtart.

Please post what version of KiXtart you are using
also the client OS it is intended to run on.
Then a sample of how you are currently doing it.

I'm sure someone here can help you get it going.

Wow Bryce... I just noticed I've posted more then you. I guess all that time off really hurt your post count. Welcome back again to the KORG [Big Grin]

[ 22. February 2003, 08:21: Message edited by: NTDOC ]

Top
#36834 - 2003-02-22 08:27 AM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
KIX 4.20
OS Win2000

This is what I'm doing

Break On

$date = @DATE ; Date in YYYY/MM/DD format

$ly = SubStr($date,1,4) ; Year in YYYY format parsed from $date
$y = SubStr($date,3,2) ; Year in YY format parsed from $date
$m = SubStr($date,6,2) ; Month in MM format parsed from $date
$d = SubStr($date,9,2) ; Day in DD format parsed from $date
$pd = ""
$sd = Val($d) ; Single digit version of day
$sm = Val($m) ; Single digit version of month

$RCCT1 = "L:\path\log_2003_" + $sm + "_" + $sd + ".txt"

$grep = "| grep32 "
$profile = Chr(34) + "I3GetProfile: Profile properties loaded:" + Chr(34)

$tail1 = "tail -f $RCCT1 $grep $profile"

If Exist('$RCCT1')
Shell '%comspec% /c start /separate $tail1'
EndIf

The script opens up another window with the tail comand but omits the grep portion. That is the part I'm stuck on.

Top
#36835 - 2003-02-22 11:24 AM Re: How to run a separate CMD window for each command
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well it looks like your attempting to get information contained in a variable of the script from a command prompt... don't think that is going to happen.

What exactly are you looking for? KiX can do searches as well.

tail
----

Similar to head, but the reverse. Prints out the last X characters (-c) or
lines in a file.

We have UDFs that do this type of searching as well.

Regardless of the method of doing it. What information are you trying to find, and once found what do you want to do with this information.

Top
#36836 - 2003-02-22 11:33 AM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
Tail allows yopu to view a log file on screen as it's being written to. That's all I'm trying to do. To see the files being written to. No searches. Not doing anything with the info afterwards. It's for monitoring purposes.
Top
#36837 - 2003-02-22 11:39 AM Re: How to run a separate CMD window for each command
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Ah.. well normally you can't see it because it is not redirected to console when certain tasks are operated in this manner.

However, I think some other members have worked on redirecting stuff to console.

Shawn or one of the other members can probably help you out more with this task.

Sorry, I have not tried to do what it is you're tyring to do.

Hopefully, one of the other members will see this post and be able to help you further.

Top
#36838 - 2003-02-22 11:45 AM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
Yes, Thanks. The command works and the output is seen in the command window. Just that it works partially. The part after the pipe does not work the way I'm trying to use it here. The command fully works when I use it in a DOS window on it's own or from a batch file. I was hoping there was a way to do it using KIX with no batch files. I wanted to keep it cleaner.
Top
#36839 - 2003-02-22 03:11 PM Re: How to run a separate CMD window for each command
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you can get it to work from the DOS prompt then it should work here too.

Since I haven't a clue what this does, I cannot test it. The way your strings are assembled, this is the command line you generate:
code:
C:\WINNT\system32\cmd.exe /c start /separate tail -f L:\path\log_2003_2_22.txt | grep32  "I3GetProfile: Profile properties loaded:"

Is this what you intended?

Also, is tail and grep32 on the path and what is the current working directory when you run it at the DOS prompt vs. running it from the script?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#36840 - 2003-02-22 03:59 PM Re: How to run a separate CMD window for each command
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
I don't believe you can grep from a tail -f, since the tail holds the output open until it is terminated.. the pipe would wait for a close. When I run the "tail -f file | grep something" at a command line, I get nothing at all. I get the same results with the DOS and Korn shells, btw.

At least, thats what appears to happen on my workstation with MKS Toolkit.

Here's my sample code (z.kix), which opens 3 windows.

"X.Kix" sits in an infinite loop writing to three files (since I don't have any other active files to monitor). It simulates your app writing to multiple log files.

"z.kix" kicks off the log generator (x.kix) and then initiates three windows to monitor the output. Once I invoke the window, I see tail displaying ALL of the lines written to the file - grep has no effect.

At least you know you aren't pulling hair out for no reason.. it's an O/S limitation. I can't get onto a *nix system now to confirm how it would work there..

Glenn

code:
 
; x.kix - simulate constant writing to 3 logfiles
Break ON

Srnd(@TICKS)

$STAT = "|","/","-","\"
$CNT = 0

while 1

$MSG = CStr(Rnd(5)) + ": some status message@CRLF"
$RTN = Open(4, "C:\Temp\File1", 5)
$RTN = WriteLine(4, $MSG)
$RTN = Close(4)

$MSG = CStr(Rnd(5)) + ": some status message@CRLF"
$RTN = Open(4, "C:\Temp\File2", 5)
$RTN = WriteLine(4, $MSG)
$RTN = Close(4)

$MSG = CStr(Rnd(5)) + ": some status message@CRLF"
$RTN = Open(4, "C:\Temp\File3", 5)
$RTN = WriteLine(4, $MSG)
$RTN = Close(4)

; display some sort of status that we're working..
$STAT[$CNT] + Chr(13)
$CNT = $CNT + 1
If $CNT = 3 $CNT = 0 EndIf

Sleep 0.5

Loop

code:
 
; z.kix - open 3 monitor windows
; Must monitor three files (file1, file2, and file3) which have status codes 1-5
; Files are written to constantly - must display all status "3" events
; Use Kix to start 3 monitor windows using "tail -f | grep 3" from Posix tools


"Starting" ?
; start the log file simulator
Shell "start kix32 c:\temp\x.kix"

; open separate windows to monitor 3 files
$FILES = "file1","file2","file3"
For Each $FILE in $FILES
$CMD = "start tail -f C:\Temp\" + $FILE + " | grep 3"
? "Monitoring $FILE"
Shell $CMD
Next

_________________________
Actually I am a Rocket Scientist! \:D

Top
#36841 - 2003-02-22 04:46 PM Re: How to run a separate CMD window for each command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
uhmm...

why you need the tail and grep there?
could do with kix too.
_________________________
!

download KiXnet

Top
#36842 - 2003-02-25 01:26 PM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
I tail some logs during my shift just to insure allication functionality from a central location (my computer), so I don't have to monitor applications on various monitors hooked through KVMs. Just saevs time and effort rather than scrolling throgh a bunch of displays. And those displays tell you less than the logs.
Top
#36843 - 2003-02-25 01:32 PM Re: How to run a separate CMD window for each command
bekoz Offline
Fresh Scripter

Registered: 2002-11-07
Posts: 20
Glenn, you can grep in a tail -f command. I do it all the time and it works. Its actually very useful for catching only the info you want.

LLigetfa, That's what I want to achieve. Let me try that. Maybe I was getting too wild with the quotes.

Top
#36844 - 2003-02-25 01:49 PM Re: How to run a separate CMD window for each command
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
There are a few potential pitfalls here.

First, the O/S. You say you have this working at the command line, so that is not a problem, but be aware that Win95 has a completely brain-dead implementation of pipe, where the output from some command is spooled to a temporary file before being passed to the next.

[edit] Deleted the overly complex sample code, as it simply works for me [/edit]

[ 25. February 2003, 17:09: Message edited by: Richard H. ]

Top
#36845 - 2003-02-25 04:45 PM Re: How to run a separate CMD window for each command
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Bekoz:

I can appreciate the concept.. I just could not get it to work here from the command line, using MKS-Toolkit. I tried it from both the CMD.EXE shell and MKS' sh.exe. Both times, while having a background task filling the logs files, I was unable to run 'tail -f file1 | grep 1'. I have the latest version of MKS for Admins installed.

What tail / grep version are you running?

Finally, in my example, I neglected to start the command with "%COMSPEC% /C", without which the pipe wouldn't work. It should be "start %COMSPEC% /c ..." so that the command interpreter opens a new window to run the commands.

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

Top
#36846 - 2003-02-25 05:17 PM Re: How to run a separate CMD window for each command
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ok, I've just tried again and is simply works for me.

A KiXtart script with the following:
code:
Shell '%COMSPEC% /C tail -f foo.txt | grep "e d"'

Waits happily, and displays matching lines if I send them with DOS commands like "echo some data >>foo.txt"

I'm using tools downloaded from various places (like Gnu-Win32). Apart from not costing anything I find they are more like their *nix counterparts than commercial offerings, and are usually more up-to-date. No support though [Wink]

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
0 registered and 867 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.07 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

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