我正在尝试编写一个调用另一个脚本的Perl脚本,该脚本读取整个目录.我没有得到任何错误,但我也没有得到预期的结果.屏幕上没有任何内容.
我不需要在屏幕上输出任何内容.我在exec()语句中调用的脚本应该将每个图像文件读入DIR目录,并创建一个文件,用于存储从该图像中提取的一些数据.exec()然后循环语句中的脚本,直到读取到目录中的所有图像.
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
my $dir = '/FilesToRead/';
my $fichier;
my $ligne;
my $mimetype;
my @listeFichiers;
my $cgi = CGI -> new();
opendir (DIR, $dir) or die "Impossible d'ouvrir $dir: $!";
@listeFichiers = grep {/\.mem$/ && -f "$dir/$_"} readdir (DIR);
while (my $ouvRep = readdir(DIR))
{
foreach $fichier (@listeFichiers)
{
exec "v-file ./param.par ./Picture/$fichier -PM_overflow 3000000" or die "Script perl ne s'est …Run Code Online (Sandbox Code Playgroud) 我刚刚尝试执行此操作:
function kill_hr(){
exec("taskkill /IM uper.exe", $output = array(), $return);
print_r($output);
echo "<br />".$return;
}
Run Code Online (Sandbox Code Playgroud)
但是,输出是这个,它不是很有用:
数组()1
当该过程不存在时,它:
Array()128
我试图弄清楚为什么当进程存在时它给我1 - 这是权限问题吗?如果是这样,我该如何纠正?
嘿,我正在尝试通过PHP在Windows上执行程序,命令发布在下面.这似乎根本没有在脚本中运行,即使在命令被手动输入命令提示符时它也能正常工作.
exec('C:\\ffmpeg -i ' . $movedfile . ' -acodec aac -ab 128k -vcodec libx264 -fpre C:\\ffmpeg\\share\\ffmpeg\\libx264-hq.ffpreset -crf 22 -threads 0 -wpredp 0' . $convertedfile);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
谢谢!
我在向函数传递参数时遇到问题,而被调用的函数没有将控制权返回给最初调用它的函数.基本上,我正在读取一个文本文件,其中包含用户名和密码到数组中.然后使用foreach循环我将用户名和密码传递给另一个函数,但这永远不会返回,只执行一组arugments;
sub batch {
open(my $in, "<", "$ARGV[0]") or die "Can't open $ARGV[0]: $!";
#Read file contents into an array.
@listOfUsers = <$in>;
foreach $listOfUsers (@listOfUsers) {
#Regex to check if txt file conforms to correct syntax.
if ($listOfUsers !~ /([a-zA-Z]{1}[a-zA-Z0-9]{3,40})\s[a-zA-Z]{1}[a-zA-Z0-9]{3,40}/) {
print "Please ensure that line $listOfUsers in $ARGV[0] is of the following syntax:\n";
print "\n<USERNAME> <PASSWORD>\n";
exit(0);
} else {
#split string and call AddUser function
my ($username, $password) = split(" ",$listOfUsers);
AddUser($username, $password);
}
}
}
sub …Run Code Online (Sandbox Code Playgroud) 我必须比较2个xml文件并使用php和Linux的diff命令生成补丁.这是我的代码:
<?php
// script file location: /var/local/out/upload.php
// ...
// $templateName file location: /var/local/out/upload/example_word_template/word/document.xml
// $filename file location: /var/local/out/upload/example_word/word/document.xml
// $templateName value: upload/example_word_template/word/document.xml
// $filename value: upload/example_word/word/document.xml
$command = "diff /var/local/out/$templateName /var/local/out/$filename > /var/local/out/patch.patch";
exec($command);
echo($command);
?>
Run Code Online (Sandbox Code Playgroud)
浏览器输出:
diff /var/local/out/upload/example_word_template/word/document.xml /var/local/out/upload/example_word/word/document.xml> /var/local/out/patch.patch
如果我复制并粘贴输出并直接在Linux中执行它,它运行得很好.但脚本本身不会生成补丁文件.可能有什么不对?
当我在我的Android设备上使用Runtime.exec并且无法弄清楚它为什么会发生时我有一个问题...
这是我做的测试的一个例子:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Runtime runtime = Runtime.getRuntime();
for(int i=0; i< 20; i++){
Log.d("TESTEXEC", "EXEC N°"+i+" : BEGIN");
try {
Process process = runtime.exec("/system/bin/ps");
process.getErrorStream().close();
process.getOutputStream().close();
process.getInputStream().close();
process.waitFor();
} catch (Throwable e) {
e.printStackTrace();
}
Log.d("TESTEXEC", "EXEC N°"+i+" : END");
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以,基本上,当这个片段工作时,它打印出来:
EXEC N°0 : BEGIN
EXEC N°0 : END
EXEC N°1 : BEGIN
EXEC N°1 : END
...
EXEC N°19 : BEGIN
EXEC N°19 : …Run Code Online (Sandbox Code Playgroud) 我使用PHP脚本上传大量文件.我正在使用CURL命令.远程服务器仅接受POST请求.但是当我执行下面的脚本时,它处理第一个请求并等待直到第一个文件上传.有没有办法使其无阻塞并同时运行2个卷曲上传请求.请参阅下面的代码示例.
<?php
$arr= array(somefile1.txt,somefile2.txt);
for ( $i=0;$i<2;$i++) {
$cmd = "curl -F name=aaa -F type=yyy FileName=@/xxxxx/xxxx/$arr[$i] http://someurl.com";
print "Executing file ";
shell_exec("nohup $cmd 2> /dev/null & echo $!" );
print "======= done ================";
}
?>
Run Code Online (Sandbox Code Playgroud) 我想使用另一个PHP脚本在后台运行PHP脚本.
我考虑到了这一点:
exec('/usr/bin/php background.php &');
Run Code Online (Sandbox Code Playgroud)
我的webhost只禁用了对exec()的访问权限.
我能想到的唯一另一种方法是将邮件()发送到通过管道传输到脚本的电子邮件转发器,但这是一个古怪的解决方法而不是解决方案.
有谁知道任何解决方案?
我正在自制外壳(非常简单的外壳)上工作。我决定采取使用execvp的方法,因为我的路径对于我的shell来说不是可变元素。我遇到了一个关于如何一次分叉和执行多个进程的逻辑问题。
我的程序应使用如下命令:
ls ; echo hello ; cat shell.c
Run Code Online (Sandbox Code Playgroud)
其中每个“;” 表示我们希望同时运行这些过程。因此,在我们的终端输出中,我们应该同时使用这些命令。
详细地说,我想解释一下我的程序如何工作:
A. Intake full command line into char array with a grab line function
B. Split the char array received from the last function by delimiters and place into an array of char arrays (pointer to pointer).
C. If one of the elements in our array of char arrays is ";" we can assume that multi commands are necessary. This is where I have trouble.
Run Code Online (Sandbox Code Playgroud)
我到目前为止已经确切地知道需要分叉多少个进程,但是我似乎无法将所有这些函数及其参数立即传递给execvp函数。我应该使用临时数组吗?我知道这不应该那么复杂,但是由于某种原因我无法弄清楚。我在下面提交我的启动函数,该启动函数接收一个char数组并根据我的“ multiCommand”变量相应地执行该变量,该变量在需要多个命令时设置(通过我的分割线函数)
int launch(char …Run Code Online (Sandbox Code Playgroud)