Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdlib>
- #include<stdio.h>
- #include<string.h>
- #include<string>
- #include <unistd.h>
- using namespace std;
- void usage()
- {
- printf("Usage: java-jar-lauch <your-jar-here>\n");
- }
- void dirUp(char* myDir)
- {
- int len = strlen(myDir);
- while (1)
- {
- len--;
- if (len == 0)
- {
- printf("Invalid folder!");
- exit(-1);
- }
- if (myDir[len] == '/')
- {
- myDir[len+1] = '\0';
- return;
- }
- }
- }
- int main(int argc, char** args)
- {
- if (argc == 1)
- {
- usage();
- return 0;
- }
- char* workingDir = new char[strlen(args[1])];
- strcpy(workingDir, args[1]);
- dirUp(workingDir);
- printf("CWD: %s\n", workingDir);
- char* cmd = new char[strlen(args[1]) + strlen("java -jar") + 2];
- sprintf(cmd, "java -jar %s", args[1]);
- printf("CMD: %s\n", cmd);
- chdir(workingDir);
- system(cmd);
- delete[] cmd;
- delete[] workingDir;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement