Windows Vista Forums

Running existing bat files

  1. #1


    PhilW Guest

    Running existing bat files

    Possibly a strange question but I have a collection of existing batch files
    that are working perfectly well but I need to call them in different a
    different order to perform different tasks. Is it possible to run these from
    PS if so how is it achieved?



    Many thanks

    Phil

      My System SpecsSystem Spec

  2. #2


    PhilW Guest

    Re: Running existing bat files

    That's great guys,

    I havn't been able to find that information on any of the MS searches I have
    done over the last day, so thanks very much (although there may be more
    questions later ;-) )

    "Shay Levy [MVP]" wrote:

    > Hi PhilW,
    >
    >
    > You can call them simply by their file name or when hosted in cmd:
    >
    > PS > d:\batch.bat
    >
    > PS > cmd /c d:\batch.bat
    >
    >
    > Pipe each file to out-null, doing so will garenty that the script won't proceed
    > until each batch file has finished excuting:
    >
    > d:\batch1.bat | out-null
    > d:\batch2.bat | out-null
    > d:\batch3.bat | out-null
    >
    >
    > out-null will also supress any output generated by the batch files.
    >
    >
    >
    >
    > ---
    > Shay Levy
    > Windows PowerShell MVP
    > http://blogs.microsoft.co.il/blogs/ScriptFanatic
    >
    >
    >
    > P> Possibly a strange question but I have a collection of existing batch
    > P> files that are working perfectly well but I need to call them in
    > P> different a different order to perform different tasks. Is it
    > P> possible to run these from PS if so how is it achieved?
    > P>
    > P> Many thanks
    > P>
    > P> Phil
    > P>
    >
    >
    >

      My System SpecsSystem Spec

  3. #3


    Shay Levy [MVP] Guest

    Re: Running existing bat files

    Hi PhilW,


    You can call them simply by their file name or when hosted in cmd:

    PS > d:\batch.bat

    PS > cmd /c d:\batch.bat


    Pipe each file to out-null, doing so will garenty that the script won't proceed
    until each batch file has finished excuting:

    d:\batch1.bat | out-null
    d:\batch2.bat | out-null
    d:\batch3.bat | out-null


    out-null will also supress any output generated by the batch files.




    ---
    Shay Levy
    Windows PowerShell MVP
    http://blogs.microsoft.co.il/blogs/ScriptFanatic



    P> Possibly a strange question but I have a collection of existing batch
    P> files that are working perfectly well but I need to call them in
    P> different a different order to perform different tasks. Is it
    P> possible to run these from PS if so how is it achieved?
    P>
    P> Many thanks
    P>
    P> Phil
    P>



      My System SpecsSystem Spec

  4. #4


    GS Guest

    Re: Running existing bat files

    But what if I want to run the visual studio command line prompt batch? I mean
    the vsvar32.bat has to set the environment variable. If a command line prompt
    were opened, executed the script, and were closed, the Windows PowerShell
    wouldn't be affected.

    "Shay Levy [MVP]" wrote:

    > Hi PhilW,
    >
    >
    > You can call them simply by their file name or when hosted in cmd:
    >
    > PS > d:\batch.bat
    >
    > PS > cmd /c d:\batch.bat
    >
    >
    > Pipe each file to out-null, doing so will garenty that the script won't proceed
    > until each batch file has finished excuting:
    >
    > d:\batch1.bat | out-null
    > d:\batch2.bat | out-null
    > d:\batch3.bat | out-null
    >
    >
    > out-null will also supress any output generated by the batch files.
    >
    >
    >
    >
    > ---
    > Shay Levy
    > Windows PowerShell MVP
    > http://blogs.microsoft.co.il/blogs/ScriptFanatic
    >
    >
    >
    > P> Possibly a strange question but I have a collection of existing batch
    > P> files that are working perfectly well but I need to call them in
    > P> different a different order to perform different tasks. Is it
    > P> possible to run these from PS if so how is it achieved?
    > P>
    > P> Many thanks
    > P>
    > P> Phil
    > P>
    >
    >
    >

      My System SpecsSystem Spec

  5. #5


    Brandon [MVP] Guest

    Re: Running existing bat files

    You should be good... it does create its own instance of cmd.exe so none of
    the enviroment variables will persist.

    I am not sure why the out-null suggestion, but Shay is pretty smart guy so I
    am sure he has a reason.

    I prefer to assign the batch to variable, just in case I want something from
    the output
    $results = d:\batch1.bat

    "GS" <GS@xxxxxx> wrote in message
    news:28AD52E5-92C8-4301-8337-C061CC615B1C@xxxxxx

    > But what if I want to run the visual studio command line prompt batch? I
    > mean
    > the vsvar32.bat has to set the environment variable. If a command line
    > prompt
    > were opened, executed the script, and were closed, the Windows PowerShell
    > wouldn't be affected.
    >
    > "Shay Levy [MVP]" wrote:
    >

    >> Hi PhilW,
    >>
    >>
    >> You can call them simply by their file name or when hosted in cmd:
    >>
    >> PS > d:\batch.bat
    >>
    >> PS > cmd /c d:\batch.bat
    >>
    >>
    >> Pipe each file to out-null, doing so will garenty that the script won't
    >> proceed
    >> until each batch file has finished excuting:
    >>
    >> d:\batch1.bat | out-null
    >> d:\batch2.bat | out-null
    >> d:\batch3.bat | out-null
    >>
    >>
    >> out-null will also supress any output generated by the batch files.
    >>
    >>
    >>
    >>
    >> ---
    >> Shay Levy
    >> Windows PowerShell MVP
    >> http://blogs.microsoft.co.il/blogs/ScriptFanatic
    >>
    >>
    >>
    >> P> Possibly a strange question but I have a collection of existing batch
    >> P> files that are working perfectly well but I need to call them in
    >> P> different a different order to perform different tasks. Is it
    >> P> possible to run these from PS if so how is it achieved?
    >> P>
    >> P> Many thanks
    >> P>
    >> P> Phil
    >> P>
    >>
    >>
    >>

      My System SpecsSystem Spec

  6. #6


    Alex K. Angelopoulos Guest

    Re: Running existing bat files

    Do you mean that you want to, from within PowerShell, open the VS-configured
    cmd.exe and keep it running? You want precisely what you have when you
    launch the VS command prompt from the start menu, but hosted in your current
    PowerShell session?

    To do that, you simply use the same command as is shown in that shortcut.
    For example, I could enter this at a PowerShell prompt for a VS 2005
    environment:

    cmd /k "c:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86

    I would then be running cmd.exe inside the PowerShell window, and can just
    type exit to close and return to PS.

    If instead you mean you want to have the VS environment variables accessible
    from within PowerShell, you actually need to perform some translation work -
    fortunately not much of it, though. The VS command prompt shortcuts
    typically point to batch files that each launch another batch file and then
    somewhere below end up launching vsvars32.bat. That file can be translated
    into a PowerShell equivalent, and it's been done before (Keith Hill, for
    example, did it over 2 years ago); details will vary, depending on platform
    bitness and VS version. For that, post back what you're after. You can also
    Google 'vsvars32' and 'PowerShell' together to get a brief set of
    discussions of previous forays into this area.


    "GS" <GS@xxxxxx> wrote in message
    news:28AD52E5-92C8-4301-8337-C061CC615B1C@xxxxxx

    > But what if I want to run the visual studio command line prompt batch? I
    > mean
    > the vsvar32.bat has to set the environment variable. If a command line
    > prompt
    > were opened, executed the script, and were closed, the Windows PowerShell
    > wouldn't be affected.
    >
    > "Shay Levy [MVP]" wrote:
    >

    >> Hi PhilW,
    >>
    >>
    >> You can call them simply by their file name or when hosted in cmd:
    >>
    >> PS > d:\batch.bat
    >>
    >> PS > cmd /c d:\batch.bat
    >>
    >>
    >> Pipe each file to out-null, doing so will garenty that the script won't
    >> proceed
    >> until each batch file has finished excuting:
    >>
    >> d:\batch1.bat | out-null
    >> d:\batch2.bat | out-null
    >> d:\batch3.bat | out-null
    >>
    >>
    >> out-null will also supress any output generated by the batch files.
    >>
    >>
    >>
    >>
    >> ---
    >> Shay Levy
    >> Windows PowerShell MVP
    >> http://blogs.microsoft.co.il/blogs/ScriptFanatic
    >>
    >>
    >>
    >> P> Possibly a strange question but I have a collection of existing batch
    >> P> files that are working perfectly well but I need to call them in
    >> P> different a different order to perform different tasks. Is it
    >> P> possible to run these from PS if so how is it achieved?
    >> P>
    >> P> Many thanks
    >> P>
    >> P> Phil
    >> P>
    >>
    >>
    >>

      My System SpecsSystem Spec

Running existing bat files

Similar Threads
Thread Thread Starter Forum Replies Last Post
Will reinstall delete existing files? Ultraclassic194 General Discussion 17 29 Sep 2008
Synctoy and existing files Zadig Galbaras Vista General 1 23 May 2008
Checking the Existing of files and their size ... follower1 PowerShell 1 28 Apr 2008
Overwriting existing files Jeanne Vista General 5 26 Sep 2007
adding files to pre-existing CD with files on it deb donr Vista music pictures video 0 24 May 2007