View Single Post
Old 11-07-2008   #5 (permalink)
RickB


 
 

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

If you find some reason to break up a script into pieces there is
nothing intrinsically wrong with that. Just be sure the top most one
is PowerShell. IOW call a .bat from .ps1, not the other way around.

On Nov 6, 7:03*pm, "IT Staff" <jkk...@xxxxxx> wrote:
Quote:

> I see, so it is better to put all batch statements into ps1 and have only
> one script running ...
>
> "Gerd Schneider" <GerdSchnei...@xxxxxx> wrote in message
>
> news:0DB8E844-7DD2-42A0-AB3C-05997D31DC66@xxxxxx
>
>
>
Quote:

> > 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
>
Quote:

> > 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.
>
Quote:

> > --
> > Gerd
>
Quote:

> > "RickB" wrote:
>
Quote:
Quote:

> >> On Nov 6, 2:53 am, "IT Staff" <jkk...@xxxxxx> wrote:
> >> > I've a batch file and a ps1 script
>
Quote:
Quote:

> >> > Test1.bat
> >> > powershell somescripts.ps1
> >> > robocopy c:\ d:\ *<filename.txt>
>
Quote:
Quote:

> >> > Somescripts.ps1
> >> > $filename = "abc.txt"
>
Quote:
Quote:

> >> > After ps1 completes, i wish to pass the $filename abc.txt *outside* to
> >> > robocopy command . Note that abc.txt was created in c:\ drive
>
Quote:
Quote:

> >> > How do i do that ? Must i use process.start method in the script ?
>
Quote:
Quote:

> >> 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.- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec