You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP执行带参数外部程序无响应:exec调用失败排查求助

Debugging Your PHP exec() Call for infekt-cmd.exe

Return code 1 from exec() almost always indicates that the underlying command failed to run properly. Let's walk through the most likely issues and fixes:

1. Quote Paths with Spaces (Critical!)

The path to infekt-cmd.exe includes spaces (C:\Program Files\iNFekt\infekt\infekt-cmd.exe), which the Windows shell will split into separate arguments if not wrapped in quotes. The same goes for your $nfoFile path if it has spaces.

Update your command to wrap both paths in escaped double quotes:

$exePath = 'C:\\Program Files\\iNFekt\\infekt\\infekt-cmd.exe';
$nfoFile = 'C:\\path\\to\\your\\file.nfo'; // Replace with your actual path

// Wrap executable and file paths in quotes to handle spaces
$command = "\"$exePath\" -S --utf-16 \"$nfoFile\"";
exec($command, $output, $return_var);

2. Capture Error Messages (See What's Actually Wrong)

By default, exec() only captures standard output (stdout). Any error messages from infekt-cmd.exe go to standard error (stderr), which is why your $output array is empty. Redirect stderr to stdout to see the issue:

$command = "\"$exePath\" -S --utf-16 \"$nfoFile\" 2>&1";
exec($command, $output, $return_var);

// Print the output to debug
print_r($output);

This will show you specific errors like "file not found" or invalid argument syntax.

3. Validate File and Executable Paths

  • Check the executable path: Double-check that infekt-cmd.exe exists at the specified location. Even Windows can be picky about case in some environments, so confirm the folder names match exactly (e.g., iNFekt vs infekt).
  • Use absolute paths for the NFO file: If $nfoFile is a relative path, PHP's working directory might not be what you expect. Use realpath() to verify the file exists and get its absolute path:
    $nfoFile = realpath($nfoFile);
    if (!$nfoFile) {
        die("Error: NFO file not found at specified path!");
    }
    

4. Verify Permissions

  • Ensure the user running PHP (e.g., IIS_IUSRS for IIS, www-data for Apache) has:
    • Execute permission on infekt-cmd.exe
    • Read permission on your NFO file
  • Check your php.ini file to make sure exec isn't listed in disable_functions (this blocks PHP from running external commands).

5. Test the Command Manually First

Open Windows Command Prompt (CMD) and run the exact command you're trying to execute in PHP. For example:

"C:\Program Files\iNFekt\infekt\infekt-cmd.exe" -S --utf-16 "C:\full\path\to\your\file.nfo"

If this fails in CMD, fix the command there first—this eliminates PHP as the source of the problem.

内容的提问来源于stack exchange,提问作者Snake Eyes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:54:30