View Single Post
Old 11-06-2008   #3 (permalink)
Gerd Schneider


 
 

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

Just a slightly more convenient procedure for the "ugly way":
Write an external temp.bat from ps1 containing
set filename=abc.txt
and add the statement
call temp.bat
to your test1.bat. This makes %filename% directly available in your
test1.bat environment

But as Rick already recommends: Better migrate the whole job to
somescripts.ps1 and do not mix ps1 and bat if they need to interact.

--
Gerd


"RickB" wrote:
Quote:

> 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