-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsomething.cpp
More file actions
51 lines (34 loc) · 1.52 KB
/
something.cpp
File metadata and controls
51 lines (34 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
int main ()
{
char filename[100];
cout << "Enter file name to compile :";
cin.getline(filename, 100);
// Build command to execute. For example if the input
// file name is a.cpp, then str holds "gcc -o a.out a.cpp"
// Here -o is used to specify executable file name
string str = "gcc ";
string helloHunnyCommand = "helloHunnyCommand";
str = str + " -o "+helloHunnyCommand + " " + filename;
// Convert string to const char * as system requires
// parameter of type const char *
const char *command = str.c_str();
cout << "Compiling file using " << command << endl<<endl;
system(command);
//cout << "\nRunning file \n";
//system("./helloHunnyCommand");
string searchStr = "[ -f /usr/local/bin/"+helloHunnyCommand+" ]";
const char *srcCommand = searchStr.c_str();
if(system(srcCommand) == 0) cout<<"FOUND the program file in /usr/local/bin"<<endl<<endl;
else cout<<"NOT FOUND the program file in /usr/local/bin"<<endl<<endl;
cout<<"Adding the program file to the /use/local/bin folder....."<<endl;
string copytobin = "sudo cp -i "+helloHunnyCommand+" /usr/local/bin";
const char *copytobinCommand = copytobin.c_str();
system(copytobinCommand);
cout<<"Adding done...."<<endl;
cout<<"Running "+ helloHunnyCommand +" as a command"<<endl;
const char *helloHunnyCommandline = helloHunnyCommand.c_str();
system(helloHunnyCommandline);
return 0;
}