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
Gert Gottschalk
  • 1,658
  • 3
  • 25
  • 37
  • 1
    PowerShell does not use `/k`, and you have the wrong slash (backwards) anyway. See [Microsoft Docs on about_PowerShell_exe](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1) and you might also find [SS64 on `CMD`](https://ss64.com/nt/cmd.html) of interest as well. – Jeff Zeitlin Sep 12 '22 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. – mklement0 Sep 12 '22 at 23:25

2 Answers2

0

Try -noexit rather than /k

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

Tom
  • 880
  • 6
  • 17
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'
SuperUser
  • 4,527
  • 1
  • 5
  • 24
  • That solution starts two windows. One with PS interactive prompt. The other with scrolling output. First window is not desired. – Gert Gottschalk Sep 12 '22 at 19:59
  • @GertGottschalk See the edit, if it's still not what you desire then update me. – SuperUser Sep 12 '22 at 20:22
  • 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? – Gert Gottschalk Sep 12 '22 at 21:36