You are here:

C++/Compiling a linux exe including a Shell Script

Advertisement


Question
I wanna create a exe(linux) which has the Shell Script and Simple CPP file which calls the Shell Script using system() function. Lets say exe name 'myInstaller' which has files myintsaller.cpp and myShell.sh. When i run the exe myInstaller , it must execute shell script. I want to do like this so i can protect my Shell Script code ,which has over 3000 lines of Code.

How do i do this ... I m in real need of this.

Answer
Hi

What do you mean by "protecting" the shell script? The script cannot be hidden.
Make sure the script is executable (-r-xr-xr-x), and is in the same directory as your compiled program. Calling the script is done like this:

for script mysh.sh
#!/usr/bin/sh
echo "Hello"

the cpp file is like this:
#include <stdlib.h>
int main()
{
  system("mysh.sh");
}

If you compile the cpp file and run the program, you will see "Hello" printed.

Perhaps you could embed the script like this example:

#include <stdlib.h>
int main()
{
  system("sh <<-EOF\necho HELLO EMBEDDED\nEOF");
}

but that would be so hard to do for a very large script.

I hope that helps.
Best regards
Zlatko  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2016 About.com. All rights reserved.