Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execSync crash on Windows with invalid paths #19

Open
justintaylor-dev opened this issue Jul 2, 2024 · 2 comments
Open

execSync crash on Windows with invalid paths #19

justintaylor-dev opened this issue Jul 2, 2024 · 2 comments

Comments

@justintaylor-dev
Copy link
Contributor

justintaylor-dev commented Jul 2, 2024

Any invalid path with an exe extension will cause PS to show an error Uncaught class std::runtime_error while executing UXP TaskQueue item: Failed to create process and then PS itself will immediately crash.

Code to repro:

const cmdCrash =`anyInvalidPath.exe`;
(await require('bolt-uxp-hybrid.uxpaddon')).execSync(cmdCrash)

If the string doesn't end in ".exe", it will reject the command with a normal error message and PS will not crash.

Also, if I correctly point to a valid command line exe like ExifTool, I am getting crashes with strings that work in Terminal.

But I can run simple non-executable commands like:

const cmd1=`set n1=100 && set n2=200 && set /A sum=n1+n2`;
(await require('bolt-uxp-hybrid.uxpaddon')).execSync(cmd1) // returns 300

As a bonus, it would be great to have Bolt return the console output for the last command / all commands and the exit code.

On MacOS, you can wrap your command in a final echo to return JSON with the exit code and the terminal output of the last command.

On Windows, it's trickier as the return string includes all commands in the same string, not just the last one.

@jardicc
Copy link
Collaborator

jardicc commented Jul 2, 2024

Isn't there any ready to use code for command line in C++ that already handles common pitfalls? E.g. how NodeJS is doing that? https://github.com/nodejs/node/blob/main/src/process_wrap.cc

@justintaylor-dev
Copy link
Contributor Author

@jardicc For sure, I was looking at going that route, but then I'd need to include a bunch of Node.js dependencies to get stuff working. Feel free to open a PR anytime though.

As a general update, got some progress on validating paths, but launching Windows processes this way still isn't working yet:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants