JosefNemec / Playnite

Video game library manager with support for wide range of 3rd party libraries and game emulation support, providing one unified interface for your games.
https://playnite.link
MIT License
8.67k stars 483 forks source link

Play Action Script for PowerShell: ErrorActionPreference Stop, but running the bare script works #3690

Closed DavidScann closed 4 months ago

DavidScann commented 4 months ago

Bug Description

I have a janky Play Action set up where it actually sends ADB commands to my phone where I will remote control it in order to play a game without the use of an emulator (it's a long story)

However, running the script with .\script.ps1 terminates the script prematurely because of the use of the adb shell monkey command in order to launch an Android package remotely.

When running the script via a terminal window, it is shown to not be an error message, and does everything as expected.

This might be a PowerShell issue, but I've tried using Invoke-Expression -Command instead of running the bare adb.exe with the ErrorAction SilentlyContinue parameter, but it does not stop the issue.

If this has nothing to do with Playnite and that there is no possible solution, my advanced apologies and thank you for your time.

To Reproduce

  1. Write a script that launches an app package using adb shell monkey. For example, .\adb.exe -d shell -n monkey -p com.nexon.bluearchive 1
  2. Save the script to a .ps1 container
  3. In Playnite, create a new Script Play Action, and execute the .ps1. For example, D:\scrcpy\script.ps1
  4. The issue should arise.

Diagnostics ID

94e94c8f-9626-405b-875e-18aedf27f74b

Screenshots

image image

JosefNemec commented 4 months ago

Use Start-Process when running and waiting for external processes, that's my only recommendation. Other than that, no idea. Playnite uses standard PowerShell 5.1 runtime and only limited exceptions apply to it compared to running standard PowerShell 5.1 terminal since it's running in "headless" mode, definitely nothing related to process execution.

DavidScann commented 4 months ago

Seems like this isn't Playnite's issue, so I'll close this issue. Guess I'll have to bug Microsoft about this or whatever 😅

JosefNemec commented 4 months ago

Have you tried using Start-Process? Also try changing working directory for the process, apps have issues if working dir is not set to their folder and script runtimes in Playnite are by default set to game's install directory (Start-Process has an argument to change working dir).

DavidScann commented 4 months ago

I'll try it later and update you on this issue as soon as I can. Thank you for the tip.

On Tue, 20 Feb 2024, 06:26 Josef Nemec, @.***> wrote:

Have you tried using Start-Process? Also try changing working directory for the process, apps have issues if working dir is not set to their folder and script runtimes in Playnite are by default set to game's install directory (Start-Process has an argument to change working dir).

— Reply to this email directly, view it on GitHub https://github.com/JosefNemec/Playnite/issues/3690#issuecomment-1954216156, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMVFP7ZLX2NSIU7DQH3GPW3YUSQBHAVCNFSM6AAAAABDP73TM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJUGIYTMMJVGY . You are receiving this because you modified the open/close state.Message ID: @.***>