我在Linux上使用Exiv2命令行工具来编辑图像元数据,如下所示:
exiv2 -M"set Iptc.Application2.Caption String This is my caption....." modify IMG.jpg
Run Code Online (Sandbox Code Playgroud)
我想使用用户提供的标题从PHP执行此操作。如果用户不输入任何特殊字符,这将起作用:
exec('/usr/local/bin/exiv2 -M"set Iptc.Application2.Caption String '.$caption.'" modify IMG.jpg');
Run Code Online (Sandbox Code Playgroud)
我需要允许用户使用特殊字符,例如单引号和双引号。我想使用escapeshellcmd()来防止恶意数据。我如何正确地转义命令和参数,以便其起作用?我尝试了很多选择,但我做对了。
我有一个PHP脚本,可以根据用户输入创建其他PHP文件.基本上,有些文件包含define可由用户翻译的特定语言常量().为了避免运行时错误,我想测试新写入的文件是否存在解析错误(由于"异常"字符序列).我已经在SO上阅读了几篇帖子(比如PHP包含解析错误的文件),并尝试了一个使用的函数
$output = exec("php -l $filename");
Run Code Online (Sandbox Code Playgroud)
确定文件是否正确解析.这在我的本地机器上完美运行,但在提供商的机器上,调用的输出exec("php ...")似乎总是空的.我尝试了一个调用ls,它给了我输出,让我假设PHP以某种方式配置为不响应命令行调用等等.有没有人知道这方面的方法?
编辑:我忘了提,我已经尝试过shell_exec,也没有结果.回应sganesh的回答:我也曾尝试过,对不起,我忘了提及.但是,输出(第二个参数)将始终为空数组,并且返回值将始终为127,无论要测试的PHP文件是否存在语法错误.
我正在尝试运行Runtime.exec()方法来运行命令行进程.
我编写了这个示例代码,它运行没有问题,但不会在c:\ tmp.txt生成文件.
String cmdLine = "echo foo > c:\\tmp.txt";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmdLine);
BufferedReader input = new BufferedReader(
new InputStreamReader(pr.getInputStream()));
String line;
StringBuilder output = new StringBuilder();
while ((line = input.readLine()) != null) {
output.append(line);
}
int exitVal = pr.waitFor();
logger.info(String.format("Ran command '%s', got exit code %d, output:\n%s", cmdLine, exitVal, output));
Run Code Online (Sandbox Code Playgroud)
输出是
INFO 21-04 20:02:03,024 - 执行命令'echo foo> c:\ tmp.txt',退出代码为0,输出:foo> c:\ tmp.txt
我试图执行此命令
echo exec("top");
Run Code Online (Sandbox Code Playgroud)
和
echo exec("/usr/bin/top");
Run Code Online (Sandbox Code Playgroud)
既不起作用(返回空白输出)
有谁知道为什么?
我正在寻找一种表达此命令的方法,该命令排除所有可执行文件,除了那些以".EXE"结尾的文件
我试图使用"find"命令和-exec来解决它.谢谢.
我尝试的命令和其他版本的命令不起作用:
find . -type f -regex "[^\.EXE$]" -printf "%f\n" -exec chmod a-x {} +
Run Code Online (Sandbox Code Playgroud)
谢谢任何帮助,Beco.
编辑:
为了找到正则表达式的"逆",我尝试了(更多)研究:
find . -type f ! -regex ".EXE$" -printf "%f\n" -exec chmod a-x {} +
Run Code Online (Sandbox Code Playgroud)
但这也行不通.
我是C的新手,我在OS类中,我需要在C(yay)中编写一个基本的shell.它实际上已经过了一半,我只是想在完成工作的同时学习C语言.
我试图在分叉后使用exec,现在调用mkdir.我需要通过一点点论证,但我一直想弄清楚,并希望有人能告诉我哪里出错了.
} else {
//fork exec
int pid = fork();
if (pid == 0) {
printf("%s",my_argv[0]);
execve("/bin/mkdir",my_argv,0);
} else wait(NULL);
}
Run Code Online (Sandbox Code Playgroud)
这是我响应mkdir调用的部分.现在,我有一个从用户输入的行[],该命令被使用
command = strtok(line, DELIMITERS);
Run Code Online (Sandbox Code Playgroud)
arg是:
arg = strtok(0,DELIMITERS);
my_argv[0] = arg;
Run Code Online (Sandbox Code Playgroud)
一切都很好,但mkdir永远不会工作.打印my_argv [0]给出了我期望的正确参数.我确定这是一个愚蠢的东西,但任何提示将不胜感激.
所有代码:
int main(int argc, char *argv[])
{
char *command;
char line[MAXLINE];
char *arg = NULL;
char *my_argv[];
while(1) {
printf(PROMPT);
if (fgets(line,MAXLINE,stdin) != NULL) {
//take out \n
line[strlen(line)-1] = '\0';
}
//looks for first delimiter, saves as the command
command = strtok(line, DELIMITERS); …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从PHP网页(目前正在使用exec())中运行可执行文件.从命令行运行时,程序采用两个参数; 我不确定用PHP运行它的最佳方法是什么.
特别是,.exe可以使用以下语法从命令行运行:
my_program.exe input_file_name.txt / output_file_name.txt
程序处理输入文件中的数据并将处理后的数据放入输出文件中.这一切都可以从命令行(在Windows中)正常工作..exe是用Visual Basic编写的(它不是由我编写的).
我知道我通常可以通过以下方式给出exec()一个参数:
exec('my_program.exe "example input parameter"');
如果编写.exe来接受输入argv(),我已经完成了测试.我试过了几件事:
$argument = "C:\wamp\www\web_dev\test\input.txt / C:\wamp\www\web_dev\test\output.txt";
exec('C:\wamp\www\web_dev\test\my_program.exe $argument');
Run Code Online (Sandbox Code Playgroud)
哪个没有成功.(我正在尝试让它在我的localhost上运行,以防相关......)
我相信,由于.exe完成了打开,写入和关闭输入和输出文件的所有工作,我只需要弄清楚如何编写将以适当的方式执行程序的PHP命令.
我见过类似的线索,所以我希望我不会再问什么了; 我无法找到与这种情况相关的线程.
编辑:如果它有帮助,我正在努力的整个范围是创建一个允许用户上传文件的Web界面,然后调用我已经给出的可执行文件(这是通过命令行指令给我的)如上所述)并为其生成具有已处理数据的输出文件.
我正在使用bash,据我所知,exec后跟一个命令应该替换shell而不创建新进程.例如,
exec echo hello
Run Code Online (Sandbox Code Playgroud)
具有打印"hello"然后立即退出的外观,因为在完成echo之后,shell进程不再返回.
如果我把它作为管道的一部分 - 例如,
exec echo hello | sed 's/hell/heck/'
Run Code Online (Sandbox Code Playgroud)
要么
echo hello | exec sed 's/hell/heck/'
Run Code Online (Sandbox Code Playgroud)
我的期望是,同样地,shell会因为其进程被替换而终止.这不是现实中发生的事情 - 上面的命令都打印"hecko"并正常返回shell,就好像"exec"这个词不存在一样.为什么是这样?
当我尝试在tcl中运行此命令时:
tar -zcvf input.scs__pmos.sdevv.tar.gz input.scs*
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
/bin/tar: input.scs*: Cannot stat: No such file or directory
/bin/tar: Error exit delayed from previous errors
child process exited abnormally
while executing
Run Code Online (Sandbox Code Playgroud)
但是,当我在Perl/shell中运行时,我得到:
perl -e 'system("tar -zcvf input.scs__pmos.sdevv.tar.gz input.scs*")'
Run Code Online (Sandbox Code Playgroud)
我明白了:
input.scs
input.scs~
Run Code Online (Sandbox Code Playgroud)
为什么Tcl造成这种情况?从LINUX Shell运行产生相同的结果.我使用Tcl 8.5
我正在尝试在我的mac上运行logstash配置文件,但每次我这样做,我都会收到此错误:
'Unknown setting 'hosts' for elasticsearch {:level=>:error}
Error: Something is wrong with your configuration.
You may be interested in the '--configtest' flag which you can
use to validate logstash's configuration before you choose
to restart a running system.'
Run Code Online (Sandbox Code Playgroud)
我正在检索JIRA数据并将其发送到elasticsearch,但即使这个简单的任务也会返回错误.这是我的代码:
input{
exec {
command => "curl -u username:password https://mycompany.atlassian.net/rest/api/latest/search?maxResults=10"
interval => 300
}
}
output{
elasticsearch{
hosts => ["127.0.0.1:9200"]
index => "test"
}
}
Run Code Online (Sandbox Code Playgroud)