Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
HI,
suppose I create a batch fileecho parent
%WINDIR%\system32\cmd.exe /k
echo childnow as the line 2 create a new shell the 3rd line do not execute in the continuation unless you 'exit' from the child shell.
I want to execute the 3rd line in the child shell. Is there any way to do that with the same batch file created. Or if there is any other method available...
thanks,
ramkrishna k.

Modify your script as below
Echo parent
Start "" cmd.exe /k
Echo while child is runningThat stems out a new shell running multitasked with its parent. However the second Echo command is still executed in the native one, not inside the child process (that may be another batch or a program).
To learn about Start type Start /? at prompt.

Thanks ivo,
Yes that is the solution. actually my question was not clear...
echo current environemtnt
%WINDIR%\system32\cmd.exe /k connect.cmd ::set up the execution environment
echo execute something in execution environemnt.I have to create a child shell as it create a execution environment after contacting to server through a specially designed script connect.cmd. Then I have to ececute the rest of the commands written in the batch file in execution environment. Also this need to be an automated process. thus I cannot write anything in the child shell. somehow it need to collect command from original batch file and execute. I don't know the way...
In the method you sugessted the rest of commands in batch files will not run in child shell and thus not in execution environment. Thus it don't help me actually..
Please suggest me something..
ramkrishna k.

Well, this may achieve your target
@Echo Off
If not%1.==@. (
Echo Parent process
Cmd /C "Connect.cmd & %~f0 @ %*")Shift /1
Echo Child shell executingThat sets up a self calling environmrnt that inherits all your native parameters along with the new ones.

Maybe I'm missing something obvious [happens alot] but it seems like you could:
@echo off
echo this is the parent
cmd /k myprog.exeOR
@echo off
echo this is the parent
start cmd /k myprog.exe
If at first you don't succeed, you're about average.M2

Sorry, too fast... too flaw, the right code is
@Echo Off
If not %1.==@. (
Echo Parent process
Cmd /C "Connect.cmd & %~f0 @ %*"
GoTo :EOF)Shift /1
Echo Child Shell executingwhere the :EOF label is the built in return point to the upper process level (Win as the calling one is the parent process).
To M2, I too does not understand why the guy wants to blow a new shell and then continue executing in that, but may be something related to the connection script (connect.cmd) dynamic.

Thanks to both IVO amd M2,
Yes the above method is working, Acrually I have found another way to do so. I want to share it, please review if there is any flaw...
To files created parentcommands.bat and childcommnds.cmd
parentcomamnds.bat:
---------------
echo set up environment variables ...
start /wait %windir%\system32\cmd.exe /c connect.cmd
exec childcommands.cmd
echo back to parent,execution ends
---------------childcommands.cmd:
---------------
echo main command execution body
---------------connect.cmd
---------------
echo a perl script that prepare execution environment by connecting to server and dowloading files by ftp
---------------here the childcommands.cmd executes in the child shell and then returns back to parent and finally the last line in parentcommands.bat executed in parent shell.
please review it. and let me know if there is any flaw....
regards,
ramkrishna k.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |