通过"计算"名称定义类属性时,如:
class C(object):
for name in (....):
exec("%s = ..." % (name,...))
Run Code Online (Sandbox Code Playgroud)
有没有一种处理众多属性定义的方法比使用exec?getattr(C,name)不起作用,因为在类构造期间没有定义C ...
我在这里发现了一个非常有用的帖子,关于在圆圈中裁剪图像.但是,当我尝试在PHP中使用exec执行imagemagick脚本时,我没有得到任何结果.我已经检查过以确保目录具有正确的权限等.我缺少一步吗?
任何见解都会非常感激.这是我的脚本的样子:
$ run = exec('convert -size 200x200 xc:none -fill daisy.jpg -draw"circle 100,100 100,1"uploads/new.png');
编辑:已安装Imagemagick.
try {
Runtime.getRuntime().exec("excel C:\\file.xls");
} catch (IOException ex) {
System.out.println(ex);
}
Run Code Online (Sandbox Code Playgroud)
不行.我必须放入excel.exe的完整路径才能工作.如何使其通用(对于任何Excel文件夹/版本)?当我使用Windows运行(开始 - >运行)从操作系统运行相同的行时,它可以工作.Java中是否有代码来模拟Windows的Run命令?
有谁知道为什么这两个语句导致显示的异常?
Runtime.getRuntime().exec("assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("ftype \"file type description\"=" + System.getProperty("user.home")+ "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");
Run Code Online (Sandbox Code Playgroud)
这是例外.
java.io.IOException: Cannot run program "assoc": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
Run Code Online (Sandbox Code Playgroud)
好吧,我已经改变了这个但仍然没有建立关联,而同一个命令是可执行的并且在cmd命令提示符下工作.
Runtime.getRuntime().exec("cmd.exe /c assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("cmd.exe /c ftype \"file type description\"=\"" + System.getProperty("user.home") + "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");
Run Code Online (Sandbox Code Playgroud)
任何补充建议?谢谢!
我想在python应用程序中执行一个程序,它将在后台运行,但最终会到达前台.
GUI用于与之交互.但是控件是通过stdin和stdout上的控制台提供的.我希望能够使用我的应用程序的GUI来控制它,所以我的第一个想法是:
这在python中是否可以轻松实现?有没有其他方法来实现我想要的,那会是什么?
我想将execve进程的退出状态0发送到启动它的进程.因为在成功时,execve永远不会回来,所以我之后无法做任何事情.但是我想,如果execve成功了.
提前致谢
我正在尝试使用imagemagick命令"convert"从.png创建一个.tif图像.
我带来的是:
$exec = "/opt/local/bin/convert -adaptive-resize 150% ".$pos.".png ".$pos.".tif";
exec($exec);
Run Code Online (Sandbox Code Playgroud)
如果我遇到CLI"哪个转换"我得到了那条路:/opt/local/bin/convert.我也试过没有路径,只有/opt/local/bin/convert -adaptive-resize 150% ".$pos.".png ".$pos.".tif和/etc/local/bin/convert -adaptive-resize 150% ".$pos.".png ".$pos.".tif.
如果我在终端中运行该命令它按预期工作,但是当我尝试从PHP脚本中使用它时,它不起作用.
编辑:我也尝试使用以下代码创建.sh文件没有成功:
#! /bin/bash
convert -adaptive-resize 150% 1.png 1.tif
convert -adaptive-resize 150% 2.png 2.tif
convert -adaptive-resize 150% 3.png 3.tif
convert -adaptive-resize 150% 4.png 4.tif
convert -adaptive-resize 150% 5.png 5.tif
convert -adaptive-resize 150% 6.png 6.tif
convert -adaptive-resize 150% 7.png 7.tif
convert -adaptive-resize 150% 8.png 8.tif
convert -adaptive-resize 150% 9.png 9.tif
Run Code Online (Sandbox Code Playgroud)
如果我从终端运行它就像一个魅力.相反,如果我尝试从一个简单的PHP文件执行它,它不会创建任何.tif文件.
<?php
$exec = "./convertpngtif.sh";
exec($exec); …Run Code Online (Sandbox Code Playgroud) 我正在使用linux来创建一个使用各种命令的shell服务.我有不同的内置命令,其中一个是"历史".我有一个reshist()函数来重置包含用户输入的输入的数组.我还想使用系统命令execvp()以及多个管道操作.
reshist()函数和多管道操作在不在一起时效果很好,但是当我同时使用它们时,会导致execvp()"坏地址"错误.
我知道reshist()函数在列表中添加输入不正常,但这不是什么大问题.问题是我收到错误的原因.
可能是什么原因?有什么更好的想法让它们一起工作?
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#define MAX_BUFFER 129 // max line buffer
#define MAX_ARGS 32 // max # args
#define SEPARATORS " \t\n" // token sparators
char *args[MAX_ARGS];
int print[16];
int get[16];
int fd[2];
char histarr[10][129]; // History array
char histel[129];
void reshist(void)
{
//HISTORY RESORTING
int counter = 0;
while (counter …Run Code Online (Sandbox Code Playgroud) 我编写了以下函数来执行snt2cooc命令(运行GIZA ++的预处理步骤之一.出于我们的目的,我认为我们可以认为snt2cooc脚本是一个黑盒子):
func SNTToCOOC(srcVocab, tgtVocab, sntPath, outpath string) error {
// open the out file for writing
outfile, err := os.Create(outpath)
if err != nil {
return err
}
defer outfile.Close()
cmdStr := "snt2cooc"
args := []string{srcVocab, tgtVocab, sntPath}
cmd := exec.Command(cmdStr, args...)
cmd.Stdout = outfile
if err = cmd.Run(); err != nil {
return err
}
cmd.Wait()
return err
}
Run Code Online (Sandbox Code Playgroud)
运行时,该函数执行时没有错误,但输出文件为空.这个代码适用于其他类似命令,但不适用于此特定snt2cooc命令,我注意到当我在shell中直接运行此命令时:
snt2cooc file1.vcb file2.vcb file3.snt
我得到以下输出:
END.
0 2
0 3 …Run Code Online (Sandbox Code Playgroud) 我想在Go中运行以下代码:
out, err := exec.Command("echo", "$PATH").Output()
Run Code Online (Sandbox Code Playgroud)
结果是:
$PATH
Run Code Online (Sandbox Code Playgroud)
而不是"PATH =/bin ..."的预期值.
为什么?我怎样才能获得预期的价值?