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

Ability to print Write-Host output? #16

Open
chmaha opened this issue Jun 7, 2023 · 2 comments
Open

Ability to print Write-Host output? #16

chmaha opened this issue Jun 7, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@chmaha
Copy link

chmaha commented Jun 7, 2023

I am using your crate to package a powershell script that installs my ReaClassical system. As you can see, the original ps1 script includes various Write-Host messages that are helpful to show progress. I wonder if that is possible with your crate somehow? Or is it a case of needing to separate the ps1 file into smaller chunks and use Rust's println!?

I tried setting .print_commands flag to true but it seems to just dump the contents of the script all at once versus actual output.

@chmaha
Copy link
Author

chmaha commented Jun 7, 2023

My workaround for now is a println! statement followed by passing chunks of the original ps1 via &str to a modified call_script function like so: call_script(include_str!("1_7zip.ps1"));. It works but the only pain is that dot sourcing obviously doesn't work for a variables.ps1 to maintain the required variables in one place. Chunking the script means that any variables in memory are wiped before the next iteration.

Maybe I'm best sticking with the powershell ps2exe module?

@cfsamson
Copy link
Owner

cfsamson commented Jun 15, 2023

Hi and sorry for the late reply. If I understand what you want correctly, it's not possible with the current design. If you look here: https://github.com/cfsamson/powershell-script/blob/cf6f40a28d0e3ddb33fb40f3bcd96650c7ac41c1/src/target/windows.rs#LL55C50-L55C50, you see that we call wait_with_output, which means that it blocks until the child process is finished and returns the output object so there is no way to show progress without dividing the script into chunks.

I think that if you fork the crate and call one of the non-blocking versions that kicks off the child process, and then pipe the output of the child process to stdout on the main process you could be able to achieve what you want, but I haven't tried that before. If you figure out a way to do that, please let me know and I could maybe create a non-blocking version of PsScript::run which allows users to monitor the state and progress of the child process.

@cfsamson cfsamson added the enhancement New feature or request label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants