Click here to Skip to main content
15,885,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found the system call to run file from disk in java. Its Runtime.getruntime.exec(). Now I need a system call to run a file from main memory.
My File is loaded in
int File[1000]; //This contains my file i.e. sequential array of byes.
int size; //This number contains file size i.e. how many bytes file has.
String filetype; // It contains file type.

Thus I have all file attributes in main memory.
(Remember file is in main memory not on the disk.)
I need to run "File[]" of size "size" and "filetype" informs me which system program to invoke.

Please tell me system call to do this job.
Posted
Comments
TorstenH. 13-Jul-12 8:07am    
sounds really strange. Probably a false approach.
What kind of "file" is that in the RAM? When in doubt - store it as temp file and then call it. that's much safer.

There isn't one. You could possibly do it via the Win32 LoadLibrary()[^] function, but it's probably more trouble than it's worth.
 
Share this answer
 
As others have mentioned, you could save the file to disk, then launch it.

You can't however just start a process from an image in memory.

It would also be unsafe to simply call the entry point of the application, as it's going to expect to own the process space. You'll prob ably find some interesting ways to crash your session this way, as the application allocates resources and remaps your address space to suit it's needs...
 
Share this answer
 
Comments
Member 8456001 19-Jul-12 15:03pm    
Fine...I have an alternate approach which will also work ::
1> I can save the file on disk.
2> Hide that file completely such that user has no access to that file.
3> Run that file by invoking associated system program.
Please note that if you even if know any website / book which will guide me for this then please suggest...
JackDingler 19-Jul-12 16:09pm    
Any admin on the machine will be able to access the file. You can't stop that.

As your running from Java, unless you already have elevated permissions, the user will be notified as to the actions you're taking.

I don't know how to save the image to a file in Java, but I can tell you the next step.

You'll run CreateProcess() and pass the file name. The OS will find the associated application for you.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900