在Tweak中如何执行系统命令呢?

比如:chmod rm ls killall 等等

system调用,好象不行,有没有别的方法?

syscall

多谢,我试试

改header可以重新用system
或者改用posix_spawn

感谢老大,学了不少知识

#import <spawn.h>

extern char **environ;

void run_cmd(const char *cmd)
{
	pid_t pid;
	const char *argv[] = {"sh", "-c", cmd, NULL};
	int status;

	status = posix_spawn(&pid, "/bin/sh", NULL, NULL, (char* const*)argv, environ);
	if (status == 0) {
		if (waitpid(pid, &status, 0) == -1) {
			perror("waitpid");
		}
	}
}

然后像调用system()一样调用run_cmd()即可

2 个赞

好!好!原来有这么多方法,非常感谢,