Search code examples
node.jsblobbufferexecchild-process

Run Buffer(.exe) without writing files in Nodejs


Suppose I had a console app in the terminal I created using C language, shouting "Hello world!" The program is called hello.exe. I upload hello.exe to static server.

Now I can download the file by typing the following address in the chrome. http://localhost:8080/hello.exe

Or I can get a Blob object using the http method in Nodejs. Is there a way to run this obtained Blob object right away without making a file? And get string Hello world!

No similar topics were found. Do I need to create and run the file and erase it right away? I want is for the files to run and not remain on my PC.


Solution

  • I'm not aware of any way to run an .exe file without first putting it on disk. You would essentially need to write your own exe loader that worked from memory instead of disk and that would be no small effort.

    Keep in mind that a client that just automatically runs some executable it gets from a URL like http://somedomain.com/hello.exe without any user intervention could be a very dangerous client as rogue web servers could send it any arbitrary executable that did all sorts of harm (viruses, ransom-ware, etc...).

    Do I need to create and run the file and erase it right away?

    Yes, erase it after the program is done running.

    I want is for the files to run and not remain on my PC.

    You will just have to clean it up at some point after it has run. If you have a programmatic client, it should be no big deal to put the file in an application-level temporary directory that your app can regular clean up. If this is from a browser, then he user controls where the file goes on disk and the user controls when it gets deleted - you can't manage that yourself from within a webpage.

    Or I can get a Blob object using the http method in Nodejs.

    You can download a binary. Not sure exactly what you're asking here.