下面的函数接受一个char指针数组Eg:arr [0]:ls arr [1]: - l arr [2]: - a arr [3]:/ etc arr [4]:NULL/*因为execvp需要最后是一个NULL*/
// function call is runCmd(arr);
函数定义如下:
void runCmd(char *arr[]){
pid_t child_pid,tpid;
int child_status;
child_pid = fork();
if(child_pid == 0){
/* The child process executes the exec*/
execvp(arr[0],arr);
/*if it returns it must have failed */
fflush(stdout);
printf("Unknown Command \n");
exit(0);
}
else {
/* let the parent wait for the child */
do{
tpid = wait(&child_status);
}while(tpid != child_pid);
}
}
Run Code Online (Sandbox Code Playgroud)
执行后我收到消息 -
ls: cannot …Run Code Online (Sandbox Code Playgroud) 我有一个托管有1and1的网站 - 谁没用!由于某种原因,他们提供的备份脚本不再有效,他们无法为我提供答案!所以我以为我会写自己的,这是我的代码:
$command = "mysqldump -u [usernameXXXX] -p [passwordXXX] [dbname] > [backupfile.sql]";
system($commmand);
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
警告:system()[function.system]:无法在第19行的/ homepages/46/XXXXXX/htdocs/admin/db_backup.php中执行空白命令
由于某种原因,此代码立即执行父命令,终止我的信号量并搞砸了我对其他程序的流控制.谁能告诉我为什么waitpid()不起作用?
//Create child processes
pid = fork();
if(pid < 0){
fprintf(stderr, "Fork Failed.\n");
exit(1);
return;
}else if(pid==0){
if(execl("/home/tropix/hw11-2","/home/tropix/hw11-2",semarg,pipe_to_p3,pipe_to_p4,(char*)0)){
fprintf(stderr, "File Exexecution of hw11-2 failed.\n");
exit(1);
}
} else {
pid = fork();
if(pid < 0){
fprintf(stderr, "Fork Failed.\n");
exit(1);
return;
} else if(pid==0){
if(execl("/home/tropix/hw11-3","/home/tropix/hw11-3",shmarg,semarg,pipe_from_p2,pipe_to_p5_1, (char*)0)){
fprintf(stderr, "File Execution of hw11-3 failed.\n");
exit(1);
}
} else {
pid = fork();
if(pid < 0){
fprintf(stderr, "Fork Failed.\n");
exit(1);
return;
} else if (pid == 0){
if(execl("/home/tropix/hw11-4","/home/tropix/hw11-4",shmarg,semarg,pipe_from_p2_2,pipe_to_p5_2, (char*)0)){
fprintf(stderr, "File Execution of hw11-4 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将GET查询的安全性添加到exec功能中.
如果我删除escapeshellarg()函数,它工作正常.如何解决这个问题?
ajax_command.php
<?php
$command = escapeshellarg($_GET['command']);
exec("/usr/bin/php-cli " . $command);
?>
Run Code Online (Sandbox Code Playgroud)
假设$_GET['command']值是run.php -n 3
我还可以添加什么安全检查?
ALTER PROCEDURE [dbo].[GetTimeSheetsAttendance]
@WhereClause varchar
AS
EXEC ('Select vwEmployeeList.ID,vwEmployeeList.Code,
tbGNClient.FName + '' '' + tbGNClient.MName + '' ''+ tbGNClient.LName as Name,
EmployeeAttendanceTb.EmpAttID, EmployeeAttendanceTb.EmpAttSetupID,
EmployeeAttendanceTb.GNClientID, EmployeeAttendanceTb.SheetID,
EmployeeAttendanceTb.Date, EmployeeAttendanceTb.TimeIn,
EmployeeAttendanceTb.TimeOut, EmployeeAttendanceTb.HasExtraTime,
EmployeeAttendanceTb.ExtraTime, EmployeeAttendanceTb.TotalOfHours,
EmployeeAttendanceTb.TotalOfCost, EmployeeAttendanceTb.Description,
vwEmployeeList.Department,
EmployeeAttendSetup.NoMaximumUnits,
EmployeeAttendSetup.NoMinimumUnits
From EmployeeAttendanceTb
LEFT JOIN vwEmployeeList on EmployeeAttendanceTb.GNClientID = vwEmployeeList.ID
LEFT JOIN tbGNClient on vwEmployeeList.ID = tbGNClient.GNClientID
LEFT JOIN EmployeeAttendSetup on EmployeeAttendanceTb.GNClientID = EmployeeAttendSetup.EmpID And EmployeeAttendanceTb.EmpAttSetupID = EmployeeAttendSetup.AttndUnitsID
' + ' ' + @WhereClause)
Run Code Online (Sandbox Code Playgroud)
注意:@WhereClause是从C#应用程序发送的参数.
DBType=nvarchar..
@WhereClause.Value= "Where EmployeeAttendanceTb.GNClientID=17"
Run Code Online (Sandbox Code Playgroud)
例外:
尝试使用数据访问应用程序块时出现一些问题,请检查以下错误消息:"W"附近的语法不正确.
也许这是一个神奇的问题.我正在尝试创建一个具有以下签名的函数(或等效的const char*const*args)
void ExecuteJavaVM(char** args){
}
Run Code Online (Sandbox Code Playgroud)
我想模拟如何execv处理参数数组,因为您可能知道execv不要求我们放置数组的最大元素数.它只是神奇地计算我们传递的数组中的元素数量作为其第二个参数.
这是execv签名.
intptr_t _execv(
const char *cmdname,
const char *const *argv
);
Run Code Online (Sandbox Code Playgroud)
某种程度上,execv设法"计算"数组argv中的元素数量.这正是我想要做的.
sizeof几乎没用,因为数组的数据类型衰减为一个简单的指针,所以sizeof很可能总是返回4.
有任何想法吗?有谁知道在哪里可以找到Windows的这些功能的来源?
最诚挚的问候,Ariel
我是Python的新手,并且一直在寻找一种方法来调用一个函数,该函数的名称由字符串和变量的组合形成,当用户选择其中一个选项时,该函数会动态填充.
例:
我用一个菜单启动程序,为用户提供某些选项(选择1,2,3或4)
如果用户选择1,变量xyz将填充一个元组或列表内的字符串.
将此字符串分配给变量,我调用另一个函数,它给了我另一个选项.
如果我得到选项1,我的代码会将xyz varible附加到预定义的字符串中,该字符串将形成一个函数名称(将在下一个调用的名称).
if int(option) == 1:
#prefixfunc will be that predefined string that will be the prefix for every function #to be called
exec('prefixfunc'+xyz'()')
#or
#eval('prefixfunc_'+xyz'()')
#for example, we have xyz as abc, then it calls function prefixfunc_abc()
Run Code Online (Sandbox Code Playgroud)
它在代码中工作正常.我不认为这对用户添加不同输入的情况可能是一种责任.由于在列表或元组中使用已定义的字符串来分配变量.
我希望我已经说清楚了.
只是为了更清楚:
def maint_car():
print('It Works!!! But did you come until here in a safe way?' )
def veh_func():
func=( "Maintenance", "Prices", "Back", "Quit" )
ord = 0
for i in func:
ord += 1
print(ord,'\b)', …Run Code Online (Sandbox Code Playgroud) 我的目录结构如下
http://domainname.com/developer/clientName/ppt/phantom/ // inside this phantom folder, all files are present
Run Code Online (Sandbox Code Playgroud)
在与Bass Jobsen聊天并查看了服务器错误日志后,我发现它列在日志中
[Tue Apr 23 08:31:34 2013] [error] [client xxx.xxx.xx.xxx] sh: line 1: 29443
Segmentation fault /home/xyz/public_html/developer/clientName/ppt/phantom/phantomjs --version 2>&1
Run Code Online (Sandbox Code Playgroud)
================================================== ================================
我正在尝试在我的服务器上执行二进制文件.调用二进制文件phantomJS,主要用于创建网页的屏幕截图.
我登录了我的cPanel,发现了有关我的服务器的以下信息:
Operating system : Linux
Architecture : i686
Run Code Online (Sandbox Code Playgroud)
所以我继续phantomjs-1.9.0-linux-i686.tar.bz2从phantomJS网站下载.我上传了phantomjs位于bin下载文件夹内的文件(我刚上传了一个名为的文件,phantomjs大小约为38 MB.我假设我不需要下载附带的任何其他文件.是一个examples文件夹和一些ReadMes和其他.txt文件)
我还将另外三个文件上传到了相同的文件夹中phantomjs:
test.php (这是将在浏览器中执行的主文件)test.js (其中包含启动phantomjs的代码)createScreenshot.php (包含输出一些HTML的代码)所以所有文件都在同一个文件夹中.因此,不应该由于错误的路径而产生问题.
exec('phantomjs test.js');
Run Code Online (Sandbox Code Playgroud)
var page = require('webpage').create();
var …Run Code Online (Sandbox Code Playgroud) 我的问题是关于C系统调用的exec系列.我如何预测正在执行的程序正在寻找什么类型的输入,因为exec系列在字符串列表arg1,arg2,arg3 ...和参数的2d char数组之间变化.大多数Linux命令行程序可以处理两种形式的输入吗?
例如:
int execl(const char *path, const char *arg0, ... /*, (char *)0 */);
int execv(const char *path, char *const argv[]);
Run Code Online (Sandbox Code Playgroud)
如果我执行ls会发生什么:
execl('/bin/ls', 'ls', NULL);
Run Code Online (Sandbox Code Playgroud)
与:
execv('/bin/ls', lsArgsArray);
Run Code Online (Sandbox Code Playgroud)
大概ls可以处理两种形式的输入,但我真正的问题是关于其他实用程序的通用,是否可以安全地假设你可以以任何方式调用它们?如果使用任何一种方法调用都不安全,那么bash会如何区分使用哪种?
我有以下问题:我在go例程中调用"cryptsetup".因此,如果cryptsetup成功并退出exitcode 0,一切正常.如果cryptsetup遇到错误,如错误的密码,并退出时出现错误代码!= 0,我的go函数只打印错误,然后退出而不会出现恐慌或错误代码.
openCmd := exec.Command("cryptsetup", "luksOpen", *container, "container")
var inPipe io.WriteCloser
if inPipe, err = openCmd.StdinPipe(); err == nil {
if err = openCmd.Start(); err == nil {
log.Println("cryptsetup command started!")
inPipe.Write([]byte(pwd))
log.Println("luks password passed!")
inPipe.Close()
log.Println("stdin pipe closed!")
if err = openCmd.Wait(); err == nil {
log.Println("Container opened!")
if err = exec.Command("mount", "-t", "ext4", "/dev/mapper/container", "/mnt").Run(); err == nil {
mountStatus.isMounted = true
pwd = ""
log.Println("Container mounted!")
return true
} else {
log.Fatalf("Couldn't mount partition: %s", err) …Run Code Online (Sandbox Code Playgroud)