0

I wrote a little java program that I want to execute when windows starts. I wrote a batch file to run when the OS starts, but I realized it won't work because windows 7 stops any batch file from running when the operating systems starts.

To get around this, I wanted to write a c program, compile it with cygwin (so that its .exe), and have this run when the operating system starts. I want it to execv the command:

java -jar ipsetup.jar

I couldn't get it to work, so I tried to just have the c program execv the "ls" command. Here is the code:

int main(int argc, char ** argv){

//argv[0] = "java";
//argv[1] = "-jar";
//argv[2] = "c:/windows/ipstartup.jar";

execv("/bin/ls", "/bin/ls");
printf("%s",strerror(errno));
return 1;

}

I keep getting the error "Bad Address" or "File or Directory does not exist." Anyone know why?

Thanks

**Edit

So I can get the program to run correctly within cygwin (it executes my java file). But when I run it in windows, it outputs only the print statement. Originally, it said cygwin1.dll was missing, so I put it in the Windows directory. Here's my source code:

#include <errno.h>
#include <stdio.h>

int main(int argc, char ** argv){

//argv[0] = "java";
//argv[1] = "-jar";
//argv[2] = "c:/windows/ipstartup.jar";


system("java -jar c:/windows/ipstartup.jar");
printf("I am here");
return 1;

}

4

1 に答える 1

1

エラーの潜在的な原因が 2 つあります。これらはバッチ ファイルの問題と似ています。Windows の起動時に cygwin や Java が機能しない可能性があります。

なぜこれを cygwin プログラムにしたのですか? system()関数と通常の ANSI Cの使用に何か問題がありますか?

于 2012-06-06T14:23:22.170 に答える