当我从 Perl 调用 cl.exe 时,为什么它不生成任何输出?

发布于 2024-08-17 03:17:36 字数 883 浏览 4 评论 0原文

我在运行 cl.exe 时遇到了一个奇怪的问题,这让我很困惑。在一个由 C/C++ 项目组成的大型 VS2008 解决方案中,我有一个项目运行一些脚本来进行一些额外的处理。该项目包含一个预构建事件,该事件调用 Perl 脚本(ActiveState Perl 在计算机上)。然后,此 Perl 脚本使用 /E 调用 cl.exe 以生成重定向到文件的预处理输出。 Perl 中的行如下所示:

my $foo = `"\path\to\cl.exe" @args.rsp >out.txt 2>err.txt`;

args.rsp 是一个纯文本文件,其中包含 cl.exe 的一堆命令行参数,包括用于获取预定义的 /E标准输出上的处理器输出。

从 VS2008 命令提示符运行时,该命令行将按预期工作。构建该项目在我的 Windows XP 计算机上也运行良好。然而,在我的新 Windows 7 机器上,当我构建项目时,out.txt 最终变成空白。我还应该补充一点,在我同事的一些 Windows 7 机器上,它运行良好,而在其他一些机器上则不然。

显然存在某种配置差异,但我不知道它可能是什么。我们检查了 VS2008 SP1 和 ActiveState Perl 的匹配版本。我在 perl 脚本中尝试了无数的解决方法 - 使用 system() 而不是反引号,使用 cl.exe /P 输出到文件,然后移动文件(文件为空),取消设置 VS_UNICODE_OUTPUT 环境变量(无效)。行为没有任何改变 - 手动运行命令行时会生成输出,但在该项目的预构建事件中运行时不会生成输出。

关于可能导致此问题的配置问题有什么想法吗?我几乎没有追求的途径。

I'm having a weird problem with running cl.exe that has me stumped. In a large VS2008 solution consisting of C/C++ projects, I have one project that runs some scripts to do some extra processing. The project consists of a pre-build event, which calls a Perl script (ActiveState Perl is on the machine). This Perl script then calls cl.exe with /E to generate preprocessed output which gets redirected to a file. The line in Perl looks like this:

my $foo = `"\path\to\cl.exe" @args.rsp >out.txt 2>err.txt`;

args.rsp is a plain text file that contains a bunch of command line args for cl.exe, including /E to get pre-processor output on stdout.

This exact command line works as expected when run from the VS2008 command prompt. Building the project also works fine on my Windows XP machine. However, on my new Windows 7 box, when I build the project, out.txt ends up blank. I should also add that on some of my coworker's Windows 7 boxes, it works fine, and on some others it doesn't.

Clearly there's some kind of configuration difference going on, but I'm at a loss as to what it may be. We've checked matching versions of VS2008 SP1 and ActiveState Perl. I've tried myriad workarounds within the perl script - using system() instead of backticks, using cl.exe /P to output to a file and then moving the file (the file is blank), unsetting the VS_UNICODE_OUTPUT environment variable (no effect). Nothing has changed the behavior - output is generated when the command line is run manually, but not when it's run inside the pre-build event for this project.

Any ideas on what kind of configuration problem may be causing this? I'm pretty much out of avenues to pursue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蝶舞 2024-08-24 03:17:37

哇,这个问题的解决方案最终比我预想的要奇怪得多。我正在使用的机器(以及其他也遇到此问题的同事)是安装了 bootcamp 和 Windows 7 的 Mac Pro。这会导致 C: 拥有 Windows 驱动器,而 E: 拥有 mac 驱动器。这会导致问题,因为预构建事件有几行测试每个驱动器号以查看那里是否有驱动器,如果有,则将 X:\Perl\bin 添加到路径中。即使 E:\Perl\bin 不存在,它也会添加到路径中。随后,perl 脚本运行,然后调用 cl.exe,由于某种原因,mac 驱动器中存在目录导致 cl.exe 失败。为什么?我不知道。无论如何,从路径中删除 mac 驱动器目录可以解决问题!

谢谢大家的眼光。

Wow, the solution to this ended up being a lot stranger than I expected. The machine I'm working on (and the other co-workers who are also experiencing the problem) is a Mac Pro with bootcamp and Windows 7 installed. That causes C: to have the windows drive and E: to have the mac drive. This causes a problem because the pre-build event has a couple lines that test each drive letter to see if there's a drive there, and if there is, adds X:\Perl\bin to the path. Even though E:\Perl\bin doesn't exist, it gets added to the path. Later, the perl script runs and then calls cl.exe, and for some reason, having a directory in the mac drive causes cl.exe to fail. Why? I have no idea. Anyway, removing the mac drive directory from the path fixes the problem!

Thanks for your eyes everyone.

三人与歌 2024-08-24 03:17:37

检查程序的退出代码。您可能希望使用 File::Spec。另外,检查 @args 是否没有进行插值。您可能想在执行之前打印命令行以检查这是否是您想要的。您的 err.txt 文件还剩下什么?

Check out the exit code of your program. You may want to build your executable name in a portable way using something like File::Spec. Also, check that @args is not interpolating. You may want to print your command line before executing to check if that's what you want. What is left your err.txt file?

柠檬心 2024-08-24 03:17:36

对我来说听起来像是 ACL 问题。您可以更改窗口来记录访问问题,然后检查事件日志以查看哪些用户遇到访问被拒绝错误。

我相信该设置位于本地政策 |审计政策|审计对象访问

Sounds like an ACL issue to me. You can change windows to log access issues and then check the event log to see what user is getting access denied errors.

I believe the setting is in Local Policy | Audit Policy | Audit Object Access

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文