View Single Post
Old 11-06-2008   #2 (permalink)
RickB


 
 

Re: How to pass values from script to external batch files

On Nov 6, 2:53*am, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> I've a batch file and a ps1 script
>
> Test1.bat
> powershell somescripts.ps1
> robocopy c:\ d:\ *<filename.txt>
>
> Somescripts.ps1
> $filename = "abc.txt"
>
> After ps1 completes, i wish to pass the $filename abc.txt *outside* to
> robocopy command . Note that abc.txt was created in c:\ drive
>
> How do i do that ? Must i use process.start method in the script ?
Powershell doesn't have a chance to help you because the limiting
factor is Test1.bat.
CMD doesn't have functionality that lets you do what you want
directly.
I can think of 4 answers.
The simplest is to put 'robocopy c:\ d:\ <filename.txt>' in
somescripts.ps1.
The next simplest is to convert Test1.bat to PowerShell.
You could also run SomeScripts.ps1 outside Test1.bat and have it call
Test1.bat with your values as arguments.
If you really MUST use CMD the way you've described I can only think
of an ugly way.
Have somescripts.ps1 write the value to a file then use FOR /F in
your .bat to retrieve/use it.
My System SpecsSystem Spec