标签: exec

exif_read_data 与 exec(exiftool...)

我有以下问题:

我在一个新继承的项目中从事维护工作。在这个项目中,开发人员通过以下方式处理图像和视频的元数据:

function getRotationFromFile($realPath) {
    $retVal = Array();

    $cmd = variable_get("exiftool",null) . "\"$realPath\"" . " | grep -E 'Rotation|Camera Identifier'";
    exec($cmd, $output);

    foreach ($output as $row){
        $key = trim(strstr($row, ':', true));
        $value = trim(str_replace(": ", "", strstr($row, ': ')));
        $retVal[$key] = $value;
    }
    return $retVal;
}
Run Code Online (Sandbox Code Playgroud)

正如您所读到的,这个函数调用exec(exiftool..)并检索一些元数据。我知道在 php 中存在exif_read_data,它做了同样的事情。

我的问题是:

  1. 最好的解决方案是什么?
  2. 谁更快?
  3. 谁是更“正确”的人?
  4. 最后,我尝试搜索,但没有找到exif_read_data是否在源代码中使用exiftool

先感谢您!

php exec exiftool

1
推荐指数
1
解决办法
3560
查看次数

正则表达式测试如何仅返回完全匹配

我有这个代码:

    var search_term = postAdminID

    // Wildcards Search
    var search = new RegExp(search_term, "i");
    sdsFilter = $.grep(sdsInfo.products, function(element, index) {
        var sted = search.exec(element.AdminID)

        return sted;
Run Code Online (Sandbox Code Playgroud)

postAdminID 是数组中特定帖子的索引。

element.AdminID 是我要搜索的相应索引。

问题:每当我尝试执行此搜索时,我都会得到每个匹配的索引以及匹配的索引的一部分。

假设我想检索索引#78。上面的代码返回:78、178、278、10078 等等。我只想要确切的索引 - 不是每个包含该索引的索引。

我已经尝试过 .exec 和测试,我查看了我能找到的 stackoverflow 上的每一篇文章。

请帮忙。如何为正则表达式指定它应该只查找整个“字符串”?

javascript regex testing jquery exec

1
推荐指数
1
解决办法
7237
查看次数

在 python 中终止使用 exec(open(file).read()) 运行的程序

在我的代码中,我从 tkinter gui 调用管道。当用户按下“运行”按钮时,整个管道开始运行。如果选择了某些设置,则会调用主 GUI 的顶层,要求提供附加文件。除非按下取消按钮或关闭窗口 X,否则这一切都有效。顶层关闭但程序继续运行。最终它会因为文件不存在而崩溃。调用 sys.exit() 不是解决方案,因为这样整个 gui 都会关闭,我只希望特定的顶层关闭并停止正在运行的文件。

如何杀死使用 exec(open(file).read()) 运行的文件而不杀死整个程序?

python tkinter exec sys

1
推荐指数
1
解决办法
1471
查看次数

Kubernetes:如何使用具有管道的 Exec 编写 livenessprobe 和 readinessprobe

我正在使用 Exec 探针添加活性探针和就绪探针。
我的配置如下:

readinessProbe:
    exec:
      command: "/usr/bin/jps -l | grep QueueProcess"
    periodSeconds: 10 
    failureThreshold: 2
    successThreshold: 2
Run Code Online (Sandbox Code Playgroud)

当上面的方法不起作用时。我对此进行了修改并尝试了:

readinessProbe:
     exec:
       command: ["/usr/bin/jps", "-l", "|", "grep","QueueProcess"]
     periodSeconds: 10 
     failureThreshold: 2
     successThreshold: 2
Run Code Online (Sandbox Code Playgroud)

运行时kubectl describe pod,得到以下输出:

  Normal   Created           37s                  kubelet             Created container app1
  Normal   Started           37s                  kubelet             Started container app1
  Warning  Unhealthy         6s (x3 over 26s)     kubelet             Readiness probe failed: invalid argument count
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]

Run Code Online (Sandbox Code Playgroud)

我尝试了另一个应用程序,我正在其中运行grpcurl来调用运行状况检查:

readinessProbe:
    exec:
      command: …
Run Code Online (Sandbox Code Playgroud)

pipe exec kubernetes readinessprobe

1
推荐指数
1
解决办法
2125
查看次数

将管道作为exec中的参数传递

我正在尝试将管道传递给另一个使用execv创建的进程.到目前为止,这是我的代码,但它不起作用.我到处寻找信息,但我找不到任何具体的关于通过管道vie exec.任何帮助表示赞赏.谢谢

int fd[2];
pipe(fd);

char passwrite[1];
sprintf(passwrite, "%d", fd[0]);

char arg[1];
arg[1]=passwrite;

int x;
x=fork();
if (x==0) {
execv("NewProg",arg);
}
Run Code Online (Sandbox Code Playgroud)

c fork pipe exec

0
推荐指数
1
解决办法
1万
查看次数

python exec问题:为什么不能连接'str'和'int'对象

我在python 2.6和2.7下测试了这些.
See this is OK:
>>> exec'e = 1'
>>> exec'f = 2'
>>> exec'g = e + f'
>>> print g
3

But this returns error:
>>> cont = ['e = 1','f = 2','g = e + f']
>>> for e in cont:
... try:
... exec e
...除了Exception, em:
... print em
...
无法连接'str'和'int'对象

所以为什么?谢谢!

python exec

0
推荐指数
1
解决办法
824
查看次数

在atexit()执行注册问题

"调用过程映像中的atexit()注册的函数未在新过程映像中注册".

这是代码:

pid = fork();
if (pid == 0) {
    atexit(check_mem);
    return execv(...);
}
Run Code Online (Sandbox Code Playgroud)

在execv()之后没有调用check_mem函数.因为上面的"线".在execv调用后得到函数的任何hacks?

在此先感谢您的帮助.

c linux exec atexit

0
推荐指数
1
解决办法
735
查看次数

使用popen2创建的杀戮过程

我正在使用函数popen2(已在stackoverflow上的其他地方推荐)以编程方式创建一个必须在一段时间后再次被杀死的进程.popen2返回一个PID,我认为这个PID可以用来杀死进程.但是,它不会以这种方式工作.为了杀死它,我必须递增返回的PID,我不明白(见下面的代码)

当各种线程并行执行此操作时,可能会出现另一个问题.在这种情况下,我认为由于竞争条件,PID可能会有不同的差异.

所以我的问题是:如何在多线程场景中可靠地识别popen2创建的进程的PID?

#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>

#define READ 0
#define WRITE 1

pid_t popen2(const char *command, int *infp, int *outfp) {

    int p_stdin[2], p_stdout[2];
    pid_t pid;

    if (pipe(p_stdin) != 0 || pipe(p_stdout) != 0)
        return -1;

    pid = fork();

    if (pid < 0)
        return pid;
    else if (pid == 0)
    {
        close(p_stdin[WRITE]);
        dup2(p_stdin[READ], READ);
        close(p_stdout[READ]);
        dup2(p_stdout[WRITE], WRITE);

        execl("/bin/sh", "sh", "-c", command, NULL);
        perror("execl");
        exit(1);
    }

    if (infp == NULL)
        close(p_stdin[WRITE]);
    else
        *infp = p_stdin[WRITE];

    if …
Run Code Online (Sandbox Code Playgroud)

c process exec popen

0
推荐指数
1
解决办法
2995
查看次数

多个execlp不起作用

我需要一些帮助.一旦我运行程序,我需要执行所有三个execlp()但发生的情况是只执行case 0.我将pid更改为1并执行case1等等.尝试将其置于for循环中但不起作用.我改变了break继续但仍然相同 - 只执行一个进程.有什么建议?

主要(){

pid_t pid;
pid= fork();
int i;

if(pid==0){

    for (i=0; i<3; i++){
        switch (i){
            case 0:
            execlp("/bin/cat", "cat", "wctrial.txt", NULL);
            break;

            case 1:     
            execlp("/bin/mkdir", "mkdir", "mydirectory", NULL);
            break;

            case 2:
            execlp("/bin/wc", "wctrial.txt", NULL);
            break;
        }
    }


}else{
    wait(NULL);
    printf("Child process completed!");
    exit(0);
}
Run Code Online (Sandbox Code Playgroud)

}

c exec

0
推荐指数
1
解决办法
1658
查看次数

调用shell脚本时,bash中的exec命令不起作用

以下是存储在同一文件夹中的两个shell脚本,两个脚本都具有执行权限:

shell1.sh

#!/bin/bash
exec shell2.sh
Run Code Online (Sandbox Code Playgroud)

shell2.sh

#!/bin/bash
pwd
Run Code Online (Sandbox Code Playgroud)

尝试执行shell1.sh时收到以下错误:

./shell1.sh: line 3: exec: shell2.sh: not found
Run Code Online (Sandbox Code Playgroud)

有什么我做错了吗?这适用于其他机器,但只是在一个特定的服务器中它无法正常工作.

任何的意见都将会有帮助.

linux bash shell exec

0
推荐指数
1
解决办法
600
查看次数

标签 统计

exec ×10

c ×4

linux ×2

pipe ×2

python ×2

atexit ×1

bash ×1

exiftool ×1

fork ×1

javascript ×1

jquery ×1

kubernetes ×1

php ×1

popen ×1

process ×1

readinessprobe ×1

regex ×1

shell ×1

sys ×1

testing ×1

tkinter ×1