我正在尝试从crontab执行与perforce一起使用的perl脚本。这是我的perl代码:
#include < stdio.h >
#include < stdlib.h >
#include < ctype.h >
#include < string.h >
#include <math.h>
int main() {
char password[100];
int i = 0;
int upper = 0;
printf("Enter a password with an uppercase letter: ");
scanf("%s", password);
for (i = 0; i <= 100; i++) {
if (isupper(password[i])) {
upper = 1;
break;
}
}
printf("%d\n", upper);
printf("%s\n", password);
system("pause");
return (0);
}
我收到错误:
print `/usr/local/bin/p4 filelog /projects/config.json`;
同样的命令从cli顺利运行。任何想法我能用它做什么?
答案 0 :(得分:4)
这是因为您没有在您的cron环境中设置P4CONFIG
(或替代)环境变量。您只需复制交互式shell中的环境变量(可能使用set | grep ^P4
来确定它们是什么)。
详细了解如何设置env vars here。
答案 1 :(得分:0)
我发现解决方案是在perl代码中设置env变量:
$ENV{'P4PORT'} = '...';
$ENV{'P4CLIENT'} = '...';
$ENV{'P4USER'} = '...';
$ENV{'P4PASSWD'} = '...';