Genymobile / Genymobile/scrcpy

Powershell Script Exits After Closing Scrcpy?

Open
#6,284 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
150k
Forks
13.7k
Avg merge
4d 13h
Merged PRs (30d)
2

Description

## Environment

- **OS:** Windows 11 24H2
- **Scrcpy version:** 3.3.1
- **Installation method:** Windows release
- **Device model:** Samsung S10e
- **Android version:** 12

## Describe the bug

I have created a powershell script to run scrcpy and do some extra contextual tasks. Issue is, once the scrcpy window is closed, it doesn't seem to return to shell to finish the rest of my script

```
$ScrcpyPath = "$Home\Desktop\PC Stuff\Tools\scrcpy-win64"
$ScrcpyConfig = "--video-source=camera --camera-id=0 --no-audio --camera-size=1920x1080 --camera-fps=$FPS --orientation=flip180 --video-bit-rate=500M --pause-on-exit=if-error -s $Serial"

Start-Process "$ScrcpyPath\scrcpy.exe" -ArgumentList $ScrcpyConfig -NoNewWindow -Wait

if (Get-Process -Name scrcpy) {
#do nothing

}
else {
Start-Process "$ScrcpyPath\adb.exe" -ArgumentList "-s $Serial shell input keyevent KEYCODE_SLEEP" -NoNewWindow
Start-Process "$ScrcpyPath\adb.exe" -ArgumentList "kill-server" -NoNewWindow

}
```
After closing the scrcpy window, it doesn't run my remaining checks/tasks (check if another instance of scrcpy is still running, if not, put my phone to sleep and kill the server). Instead it stops here:

```
INFO: Camera video source: control disabled
INFO: ADB device found:
INFO: --> (usb) R58M22BYENL device SM_G970W
C:\Users\USER\Desktop\PC Stuff\Tools\scrcpy-win64\scrcpy-server: 1 file pushed, 0 skipped. 88.9 MB/s (90788 bytes in 0.001s)
[server] INFO: Device: [samsung] samsung SM-G970W (Android 12)
INFO: Initial display orientation set to flip180
[server] INFO: Using camera '0'
INFO: Renderer: direct3d
INFO: Texture: 1920x1080
WARN: Killing the server...
```

UPDATE: looks like this is only an issue when using Start-Process in powershell to run scrcpy. If ran with .bat like language, it works fine

```
.\Scrcpy --video-source=camera --camera-id=0 --no-audio --camera-size=1920x1080 --camera-fps=$FPS --orientation=flip180 --video-bit-rate=500M --pause-on-exit=if-error -s $Serial
```

```
scrcpy 3.3.1
INFO: Camera video source: control disabled
* daemon not running; starting now at tcp:5037
* daemon started successfully
INFO: ADB device found:
INFO: --> (usb) R58M22BYENL device SM_G970W
C:\Users\USER\Desktop\PC Stuff\Tools\scrcpy-win64\scrcpy-server: 1 file pushed, 0 skipped. 6.9 MB/s (90788 bytes in 0.013s)
[server] INFO: Device: [samsung] samsung SM-G970W (Android 12)
INFO: Initial display orientation set to flip180
[server] INFO: Using camera '0'
INFO: Renderer: direct3d
INFO: Texture: 1920x1080
WARN: Killing the server...
Get-Process : Cannot find a process with the name "scrcpy". Verify the process name and call the cmdlet again.
At C:\Users\USER\Desktop\PC Stuff\Scripts\Webcam Launcher.ps1:30 char:5
+ if (Get-Process -Name scrcpy) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (scrcpy:String) [Get-Process], ProcessCommandException
+ FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand

PS C:\Users\USER\Desktop\PC Stuff\Tools\scrcpy-win64>
```

I've changed scrcpy to run like this in my script so it returns to shell properly + can read the switches in $ScrcpyConfig

```
Invoke-Expression ".\scrcpy $ScrcpyConfig"
```

Looks like this may just be an ADB thing. Happens with .\adb.exe as well

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the reported Windows behavior using the PowerShell Start-Process calls for scrcpy.exe and adb.exe, then compare it with the direct .\scrcpy invocation shown in the issue. Start with the scrcpy and adb process-exit behavior around -Wait; done means the shell resumes after the window closes and the remaining PowerShell checks run as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, powershell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.