gpt4 book ai didi

c - 在 C 中导入 bash 模块

转载 作者:行者123 更新时间:2023-11-30 15:30:11 25 4
gpt4 key购买 nike

我是编程初学者,但我更熟悉 python 和 bash,如果我想在 python 中使用 bash,我会使用 import os 并使用 bash 我会使用 os.system(“#code#”)。我如何在 C 中做到这一点?我使用的是 linux mint 17。

最佳答案

我认为您可以使用 system() 调用来执行 shell 脚本。像这样的东西

int main()
{
system("echo hello"); //system("your shell script")
}

这样你就可以将你的shell脚本存储在一个文件中,在c中打开该文件,逐行读取并执行它..

关于c - 在 C 中导入 bash 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25745166/

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