gpt4 book ai didi

php - 将 PHP 变量传递给 Bash 脚本,然后启动它

转载 作者:行者123 更新时间:2023-11-29 08:48:21 27 4
gpt4 key购买 nike

所以,基本上,我想做的是执行这个 Bash 脚本:

#!/bin/bash

path="./"
filename="Ellly.blend"
file=${path}${filename}
description="Test of the api with a simple model"
token_api="ff00ff"
title="Uber Glasses"
tags="test collada glasses"
private=1
password="Tr0b4dor&3"

curl -k -X POST -F "fileModel=@${file}" -F "filenameModel=${filename}" -F "title=${title}" -F "description=${description}" -F "tags=${tags}" -F "private=${private}" -F "password=${password}" -F "token=${token_api}" https://api.sketchfab.com/v1/models

在 PHP 函数中。问题是,我真的不知道如何向它传递一些变量,然后等待它结束,然后再恢复 PHP 函数。

有什么帮助吗?

最佳答案

注意:我没有做所有的设置,我希望你能理解。

选项 1:传递参数

PHP:

$file = escapeshellarg($file);
$filename = escapeshellarg($filename);
// escape the others
$output = exec("./bashscript $file $filename $tags $private $password");

bash :

#!/bin/bash
filename=$1
file=$2
description="Test of the api with a simple model"
token_api="ff00ff"
title="Uber Glasses"
tags=$3
private=$4
password=$5

...

选项 2:使用环境变量

PHP:

putenv("FILENAME=$filename");
putenv("FILE=$file");
putenv("TAGS=$tags");
putenv("PRIVATE=$private");
putenv("PASSWORD=$PASSWORD");

$output = exec('./bash_script');

bash :

filename=$FILENAME
file=$FILE
description="Test of the api with a simple model"
token_api="ff00ff"
title="Uber Glasses"
tags=$TAGS
private=$PRIVATE
password=$PASSWORD

...

关于php - 将 PHP 变量传递给 Bash 脚本,然后启动它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13903506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com