Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute BATCH script in a programs memory

I am currently faced with a problem, I need to execute a batch script within a programs memory (so it does not have to extract the batch file to a temporary location).

I am open to solutions in C# and C++

Any help would be appreciated

like image 578
Peter Avatar asked Apr 20 '26 04:04

Peter


2 Answers

cmd.exe won't run a script from the memory of your process. The options which seem most obvious to me are:

  1. Relax the constraint that stops you extracting the script to a temporary file.
  2. Compress your script into a single line and use cmd.exe /C to execute it. You'll need to use the command separator &&.
  3. Write your own batch command interpreter.
  4. Use a different scripting language.

Options 3 and 4 aren't really very attractive! Option 1 looks pretty good to me but I don't know what's leading to your constraint.

like image 195
David Heffernan Avatar answered Apr 21 '26 16:04

David Heffernan


Open a pipe to the command shell and write the program code into that pipe. Here is an example: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351

like image 35
ceving Avatar answered Apr 21 '26 18:04

ceving



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!