I have this problem:
To complile and run Java programs I must do the following:
In cmd.exe run comand
path C:\Program Files\Java\jdk1.7.0_75\bin
Then I must complile program:
C:\Documents and Settings\Java\HelloWorld>javac HelloWorld.java
...and run:
C:\Documents and Settings\Java\HelloWorld>java HelloWorld
In order not to follow these steps, I write simple C program:
#include <stdio.h>
#include <stdlib.h>
#define _JAVA
#define JAVAC
int main(int argc, char *argv[])
{
char comand[261];
if(argc < 2)
{
printf("Error: not enougth arguments. Example: %s <java program name>\n", argv[0]);
return 0;
}
system("path \"C:\\Program Files\\Java\\jdk1.7.0_75\\bin\"");
#ifdef JAVA
sprintf(comand, "java \"%s\"\0", argv[1]);
#elif defined JAVAC
sprintf(comand, "javac \"%s\"\0", argv[1]);
#else
#error must defined JAVA or JAVAC
#endif
system(comand);
return 0;
}
But it is not work: cmd does not see "java" or "javac".
How can I fix it?
javaandjavacto yourenvironment variables?control panel. Just google it.system()cannot see the modification of thepathvariable. See stackoverflow.com/questions/245600/… and try to run both commands in a singlesystem()call.