Computing.Net > Forums > Programming > how to pass command to child shell?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to pass command to child shell?

Reply to Message Icon

Name: ramkrishna836152
Date: September 26, 2005 at 00:00:46 Pacific
OS: Windows server 2003 sp1
CPU/Ram: Intel P4 3Ghz, 1GB RAM
Comment:

HI,
suppose I create a batch file

echo parent
%WINDIR%\system32\cmd.exe /k
echo child

now 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.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: September 26, 2005 at 02:36:32 Pacific
Reply:

Modify your script as below

Echo parent
Start "" cmd.exe /k
Echo while child is running

That 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.


0

Response Number 2
Name: ramkrishna836152
Date: September 26, 2005 at 04:13:07 Pacific
Reply:

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.


0

Response Number 3
Name: IVO
Date: September 26, 2005 at 05:34:17 Pacific
Reply:

Well, this may achieve your target

@Echo Off

If not%1.==@. (
Echo Parent process
Cmd /C "Connect.cmd & %~f0 @ %*")

Shift /1
Echo Child shell executing

That sets up a self calling environmrnt that inherits all your native parameters along with the new ones.


0

Response Number 4
Name: IVO
Date: September 26, 2005 at 05:37:50 Pacific
Reply:

Beware there is a space between

not and %1.



0

Response Number 5
Name: Mechanix2Go
Date: September 26, 2005 at 07:25:25 Pacific
Reply:

Maybe I'm missing something obvious [happens alot] but it seems like you could:

@echo off
echo this is the parent
cmd /k myprog.exe

OR

@echo off
echo this is the parent
start cmd /k myprog.exe



If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: IVO
Date: September 26, 2005 at 12:01:23 Pacific
Reply:

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 executing

where 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.


0

Response Number 7
Name: ramkrishna836152
Date: September 26, 2005 at 23:17:22 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: how to pass command to child shell?

Batch: how to assign command to Var www.computing.net/answers/programming/batch-how-to-assign-command-to-var/11248.html

pass command line arg through JSP www.computing.net/answers/programming/pass-command-line-arg-through-jsp/5525.html

how to manipulated windows command www.computing.net/answers/programming/how-to-manipulated-windows-command/14736.html