cuốn sách gpt4 ai đã làm

linux - 期待 linux 上的脚本

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-04 12:49:15 27 4
mua khóa gpt4 Nike

我想制作一个可以使用 srand 函数回答问题的 expect 脚本。

例如,我将使用 netcat 连接到服务器,我将从服务器收到一个问题,例如“请输入 0 或 1”;然后我希望我的脚本可以使用上面的代码自动回答问题。

  #include 
#include
#include
#include

khoảng trống chính(){
int số;
srand(thời gian(NULL));
num=(rand()%2);
printf("%d\n",num);}

如果您能提供一些示例,那将非常有帮助。非常感谢。

câu trả lời hay nhất

您想启动 netcat,识别该文本,然后在 (0,1) 中返回一个随机值,是吗?

#!/usr/bin/env expect
expr {srand([clock seconds])} ;# initialize RNG
spawn netcat 127.0.0.1
expect "please enter 0 or 1"
send "[expr {int(rand() * 2)}]\r"
mong đợi

参见文档:http://tcl.tk/man/tcl8.6/TclCmd/expr.htmhttp://tcl.tk/man/tcl8.6/TclCmd/mathfunc.htm

Tcl 的 expr 命令因为是 Tcl 中的独立迷你语言而受到一些批评。语法可以……稍微清理一下。

#!/usr/bin/env expect
namespace import ::tcl::mathfunc::*
namespace import ::tcl::mathop::\*
srand [clock seconds] ;# initialize RNG
spawn netcat 127.0.0.1
expect "please enter 0 or 1"
send "[int [* 2 [rand]]]\r"
mong đợi

关于linux - 期待 linux 上的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37742937/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress