在任务调度程序中运行C程序时出错
我编写了一个 C 程序来离线获取图像并将其保存在使用 fopen/fread/fwrite 和 libcurl 的文件中。一切都编译得非常好,我可以通过双击程序完美地运行它。但是,当我尝试使用任务计划程序在计算机上设置任务每 10 分钟运行一次时,程序将打开,并且当它尝试保存文件时出现错误:
异常::句柄:异常:STATUS_ACCESS_VIOLATION open_stackdumpfile:将堆栈跟踪转储到 Garden.exe.stackdump
我正在运行 Windows Vista,并尝试使用本机 Windows 计划任务功能。我已选中任务属性中标记为“以最高权限运行”的框。
I made a C program to get an image offline and save it in a file using fopen/fread/fwrite and libcurl. Everything compiles perfectly fine and I can run it perfectly fine by double clicking the program. But, when I try and set a task on my computer using task scheduler to run it every 10 minutes, the program opens and when it tries to save the file I get the error:
exception::handle: Exception: STATUS_ACCESS_VIOLATION
open_stackdumpfile: Dumping stack trace to garden.exe.stackdump
I am running Windows Vista, and attempting to use the native Windows Scheduled Tasks feature. I have checked the box marked "Run with highest privileges" in the task properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,无论您的程序正在运行什么,都是从您没有写入权限的目录中执行的。没有“garden.exe.stackdump”文件的事实给出了这一线索。
将其保存到文件时,是将其保存为
fopen("myfile","w")
还是使用完全限定名称?例如,假设您要保存的文件名为“foobar.png”,并且您想将其保存到您在下面命名的目录中,您会得到类似的内容:由于您的程序似乎也将错误转储到文件中同样,您最好在程序开始时使用
chdir("/home/myname")
,以便将任何“.stackdump”文件放置在您有权访问的位置。您可能需要考虑的另一件事是您的任务计划程序可能以
nobody
或其他一些被剥夺权限的帐户运行您的脚本。如果是这种情况,您需要在fopen
和chdir
中使用全局可写区域的完整路径(例如/tmp
)或具有开放权限的工作目录。例如:(您在主目录上设置执行位,以便无权限程序可以访问其子目录,即使它无法读取其中的任何内容。)
My guess is that whatever is running your program is doing so from a directory to which you don't have write permissions. The fact that there is no "garden.exe.stackdump" file gives that as a clue.
When you save it to a file, are you saving it as
fopen("myfile","w")
or are you using a fully qualified name? For example, let's say that the file you want to save is called "foobar.png" and you want to save it to the directory you named below, you'd have something like:Since your program also seems to dump errors to a file as well, you might do well to
chdir("/home/myname")
at the start of your program so that any ".stackdump" files get placed where you have access.The other thing you might want to take into account is that your task scheduler may be running your script as
nobody
or some other permissions-deprived account. If that's the case, you'll want to use a full path infopen
andchdir
to a globally writable area (such as/tmp
) or a working directory with open permissions. For example:(You set the execute bit on your home directory so that the permission-less program can get access to its subdirectory even though it can't read anything in it.)