0

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
  • 1
    PowerShell does not use /k, and you have the wrong slash (backwards) anyway. See Microsoft Docs on about_PowerShell_exe and you might also find SS64 on CMD of interest as well. Commented Sep 12, 2022 at 19:21
  • In short: When calling PowerShell's CLI (powershell.exe for Windows PowerShell, pwsh for PowerShell (Core) 7+) from the outside, using (possibly implied) -Command / -c, you need to escape " chars. you want passed through as part of the command: \" works in principle, but can break when calling from cmd.exe. In that case, use "^"" (sic) with powershell.exe, and "" with pwsh.exe, inside overall "..." quoting. See the linked duplicate for details. Commented Sep 12, 2022 at 23:25

1 Answer 1

0

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' 
Sign up to request clarification or add additional context in comments.

3 Comments

That solution starts two windows. One with PS interactive prompt. The other with scrolling output. First window is not desired.
@GertGottschalk See the edit, if it's still not what you desire then update me.
Proposed code starts window but throws error message about '-av' option (See above UPDATE2). Those are legal in rsync but seems got interpreted by the shell?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.