Start-Process delay ArgumentList

Copper Contributor

Hi, I'm using a power shell to run a OpenSSL batch but I have some problems.

 

The basic OpenSSL batch needs to load after it opens and then you can write the command string.

The string works if I do it manually, but in Powershell no.

 

Here is my code:

 

Start-Process -FilePath "$mypath/start.bat" -ArgumentList "/c $myString"

 

I'm afraid the Argument are passed too soon and the OpenSSL isn't loaded yet (the batch opens). Is there a way to open the bat (like Invoke-Item) and pass the arguments after 4 seconds?

 

Thanks in advance for the help

5 Replies

Hi @Darkveemon1,

to address this, you can try a combination of Start-Process and Start-Sleep to introduce a delay between launching the batch file and passing the arguments.

 

# Launch the start.bat file
Start-Process -FilePath "$mypath/start.bat" -Wait

# Wait for 4 seconds
Start-Sleep -Seconds 4

# Pass the command string to the already running OpenSSL process
Invoke-Expression "$myString"

 

 

Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.


If the post was useful in other ways, please consider giving it Like.


Kindest regards,


Leon Pavesic
(LinkedIn)

Hi, thanks for the reply, unfortunately it is still not working. This time I get an error, it seems it tries to do "Invoke-Item" and launch the code from Powershell and not from the OpenSSL batch and so it fails.

My code to decrypt uses an "&" and in Powershell it is not managed like that, that's why it should launch it in the batch
I managed to do it in a more unorthodox way, but it worked
And how? :)
Could you share your unorthodox way with us?