简体   繁体   中英

Cygwin C File returns “Bad Address” when using execv

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 ac 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;

}

I can see two potential sources of error here and they are similar to the batch file problem: cygwin and/or java might not work at Windows startup.

Why did you make this a cygwin program? Is there something wrong with using the system() function and regular ANSI C?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM