Windows bat file to open new window and launch script

Viewed 39

Tools : Windows 7 & powershell & Rsync

Goal : Create a bat file to launch rsync in such a way that the output is scrolling in the new window. Once command terminates the window shall remain open for inspection.

Tried this code :

start powershell \k C:\Program Files2\Git\usr\bin\rsync.exe -av /d/Images/Dia_scans /f/Shiva_D/Images

When double click on the bat file there seems to be a short popup. But it closes and then nothing happens.

What's missing?

UPDATE:

Following works in cmd:

start cmd /K "C:\Program Files2\Git\usr\bin\rsync.exe" -av /d/Images/Dia_scans /f/Shiva_D/Images

But desire is to use powershell:

start powershell -NoExit "C:\Program Files2\Git\usr\bin\rsync.exe" -av /d/Images/Dia_scans /f/Shiva_D/Images

Throws this error:

The term 'C:\Program' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:11
+ C:\Program <<<<  Files2\Git\usr\bin\rsync.exe -av /d/Images/Dia_scans  /f/Shiva_D/Images
+ CategoryInfo          : ObjectNotFound: (C:\Program:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

What is proper quotation rule for powershell vs cmd when path / argument has space char?

UPDATE2:

Proposed code:

start powershell -NoExit Start-Process -NoNewWindow "C:\Program Files2\Git\usr\bin\rsync.exe -av --delete /d/Images/Dia_scans /f/Shiva_D/Images"

Gives popup window with this error.

    Start-Process : A parameter cannot be found that matches parameter name 'av'.
At line:1 char:71
+ Start-Process -NoNewWindow C:\Program Files2\Git\usr\bin\rsync.exe -av <<<<
--delete /d/Images/Dia_scans /f/Shiva_D/Images
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

UPDATE3/CLOSING

It's easier to user cmd. I am abandoning powershell for now. Using this code in cmd works fine and is reasonably intuitive.

start cmd /K "C:\Program Files2\Git\usr\bin\rsync.exe" -av --delete /d/Images/Dia_scans /f/Shiva_D/Images
2 Answers

Try -noexit rather than /k

For testing run your command in an already open cmd window so you'll see any errors.

You need to escape the spaces.

For example:

start powershell -NoExit & "C:\Program Files2\Git\usr\bin\rsync.exe" -av /d/Images/Dia_scans /f/Shiva_D/Images

EDIT:

Forgot about the goal... Try to use -NoNewWindow

start powershell -NoExit Start-Process -NoNewWindow "C:\Program Files2\Git\usr\bin\rsync.exe" -av /d/Images/Dia_scans /f/Shiva_D/Images

EDIT2::

start powershell -NoExit Start-Process -NoNewWindow "C:\Program Files2\Git\usr\bin\rsync.exe" -ArgumentList '-av /d/Images/Dia_scans /f/Shiva_D/Images'
Related