简体   繁体   English

如何创建一个脚本,该脚本将接收用户输入并在使用python 3.6的终端命令中使用该脚本?

[英]How do I create a script that will take user input and use it in a terminal command using python 3.6?

I'm trying to write a script in python3.6 on linux that takes a user's input (in the form of a URL), then performs the 'whois' terminal command on the input provided. 我正在尝试在Linux上的python3.6中编写一个脚本,该脚本接受用户的输入(以URL的形式),然后在提供的输入上执行“ whois”终端命令。 I'm trying to launch it from IDLE. 我正在尝试从IDLE启动它。 The best I've got is: 我最好的是:

import os
os.system("clear")
os.system("gnome-terminal -e 'bash -c \'")
w = ""
w = (input("Who is your target?" ))
os.system("whois " + w)

It seems that after taking the input, the gnome terminal doesn't open, and nothing happens. 似乎在输入之后,gnome终端没有打开,什么也没有发生。 I'm not very experienced in python at the moment and I'm struggling quite a bit with this! 目前,我对python的了解还不是很丰富,为此我正苦苦挣扎!

I modified your code a bit: 我对您的代码做了一些修改:

import os
os.system("clear")
w = ""
w = (input("Who is your target? "))
os.system("whois "+w)

Here is the demo: 这是演示:

演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 python 脚本的终端中获取存储在文件(例如 *.inp)中的多个“用户输入” - How to take multiple "user input" stored in a file (e.g., *.inp) in terminal for python script 如何在我的 python 脚本中创建终端命令? - How do I create terminal commands in my python script? 如何将列表中的用户输入作为 Python 3 中的整数 - How do I take user input in a list as integers in Python 3 如何从终端获取python脚本的输入文件? - How to take input file from terminal for python script? 在 python 中运行终端命令后,如何将用户输入终端? - How can I give a user input into terminal after running a terminal command in python? 如何在命令行上接受用户输入的python脚本而不是提示 - How do I accept user input on command line for python script instead of prompt 如何使用python向当前终端历史记录添加命令? - How do I add a command to current terminal history using python? 如何扩展此python脚本以通过命令行而不是提示来接受用户输入? - How to extend this python script to take in user input by command line instead of prompting? 如何将一个python脚本的输出作为另一个python脚本的用户输入 - How can i take the output of one python script as user input for another python script 如何获得Python程序以将参数作为来自UNIX终端的标准输入的输入? - How do I get a Python program to take in parameters as inputs that come from standard input from the UNIX terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM