Posts: 42
Score: 0
Joined: 12/6/2006
From: Grand Rapids, MI
Status: offline
I want to be able to start a 2nd script from within another script. The 2nd script needs to be able to send information to stdout. When the 1st script ends, I want to be able to programmatically terminte the 2nd script from wiithin the 1st. Here are my simple eval scripts:
----
In one.vbs, you can control starting two.vbs using either .Run or .Exec by setting useRun to True or False respectively.
Finally, here is my problem:
When I use .Run, the wscript.echo strings are output to the command window. This is what I want. But I can't seem to find a way to then terminate two.vbs from within one.vbs.
When I use .Exec, the wscript.echo strings are not output to the command window (I am not sure where they are going, but it probably has something to do with the fact that the object created by .Exec allows the spawning program to fiddle with Stdout and Stdin). But, using .Exec I can terminate the 2nd script from within the first using the .Exec object's Terminate() method.
So can anyone suggest how I can solve either problem? In particular, is there really no way to programmatically terminate programs that are started with the .Run method?
Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you're trying to do this as a progress bar you should be able to find other methods in this and other forums. However if you want to use this method then I guess you could try the following.
1. launch script1 from your desktop so that it uses wscript.exe 2. execute script2 using cscript.exe as you currently have it 3. when you want to terminate it, use the wmi class "win32_process" to terminate cscript.exe
and actually if you launch your second script using the exec method you can get the PID (process id) which you can then use in conjunction with the win32_process class to terminate your specific instance of cscript.exe should you have several open.
Posts: 42
Score: 0
Joined: 12/6/2006
From: Grand Rapids, MI
Status: offline
Well I wanted to keep this post as simple as possible to focus on my two questions. What will really be implemented is one.vbs above will be the Quick Test Professional (QTP) automated test tool, an app used to write automated GUI test scripts. two.vbs will be my implementation of the Unix tail program. QTP will spawn tail to monitor an output log created during each (sometimes very long) test run, and update its cmd window as the log is appended by QTP.
Anyway, I would like to stay focused on the two simple vbScript files I posted in the thread starter, and to add a few lines of code as is needed to these scripts in order to answer one of the following questions:
1. How do you, or can you, terminate a program started by the .Run command?
2. In my posted example, two.vbs outputs it's wscript.echo text to the cmd window when it is started with .Run in one.vbs. But when it is started using .Exec the wscript.echo text is not displayed in its cmd window. So, (a) where is that text going, and (b) is there something I can do to get this output displayed in the two.vbs command window?
-Thanks, Terry
P.S. I have prowled this forum for my answers and found none (but again I have not been very successful in asking the write search questions in the past).
Posts: 42
Score: 0
Joined: 12/6/2006
From: Grand Rapids, MI
Status: offline
quote:
ORIGINAL: thorwath 2. In my posted example, two.vbs outputs it's wscript.echo text to the cmd window when it is started with .Run in one.vbs. But when it is started using .Exec the wscript.echo text is not displayed in its cmd window. So, (a) where is that text going, and (b) is there something I can do to get this output displayed in the two.vbs command window?
Well, some more prowling on the web inidicates that my initial assumption that the .Exec stdOut property does is in fact snag all echo output, as per:
I now see the intended use of .Exec is to run command line programs silently and then let the invoker read status, and the stdX channels as the spawned program runs and then finishes. So it now appears that I need to use .Run to achieve my two goals (have two.vbs output is echo text to its command window, and eventually terminate two.vbs from one.vbs). But, is there any simple way (short of the scanning for pids as recommended in the first reply) to programmatically terminate a program started with .Run?
Or do I need to implement a file or env var flag, written by one.vbs, and occassionally read by two.vbs, that tells. two.vbs to terminate itself?
Posts: 2721
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I'm not aware of a way to terminate your second .vbs from within the first. You don't need to scan for a PID since it is automatically given to you if you use the exec method. see: http://msdn2.microsoft.com/en-us/library/x78640t0.aspx.
"do I need to implement a file or env var flag, written by one.vbs, and occassionally read by two.vbs, that tells. two.vbs to terminate itself?"
I think this would definetly be an alternate method.