【发布时间】:2023-03-19 01:17:01
【问题描述】:
我正在 c++ 上编写一些函数,用于编译器少到 css。
我安装了nodejs、less。
我创建了一个less文件test.less
@color: red;
a{color:@color;}
当我在终端上运行命令时:
lessc test.less test.css
它创建了一个名为 test.css 的文件 css,但是当我通过 c++ 运行此命令时,它返回错误。请帮我。这是我的 C++ 函数:
std::string shell_exec( std::string cmd )
{
std::string result = "";
FILE* pipe = popen(cmd.c_str(), "r");
if (pipe == NULL)
{
return result;
}
char buffer[128];
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe) != NULL)
{
result += buffer;
}
}
pclose(pipe);
return result;
}
shell_exec("lessc test.less test.css");
我有一个错误:
/usr/bin/env: node: No such file or directory
/usr/bin/node 已存在。
================ 更新:固定===================
谢谢@Bass Jobsen,@Lightness Races in Orbit
我通过添加lessc和nodejs的绝对路径来修复
shell_exec("/usr/bin/node /usr/bin/lessc test.less test.css");
【问题讨论】:
-
我真的不相信它可以在终端上工作,但不能在你的 C++ 程序中工作。
-
@LightnessRacesinOrbit 这是真的。