不喜欢这个问题:Calling a python script from command line without typing "python" first
我有一个名为argparse_test.py的Python脚本。我把它放在我的Windows 10机器上的系统路径中,这样我只需输入" arparse_test.py"就可以从任何文件夹中调用它。然后是争论。
如果我打电话
,这个论点就有用了python argparse_test.py -w
但是当我打电话
时,它无法识别参数argparse_test.py -w
有没有办法让这项工作?
脚本:
import argparse
import time
if __name__=='__main__':
# Command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--work", action="store_true", help="Make it work")
args = parser.parse_args()
if args.work:
print "It works"
else:
print "It doesn't work"
time.sleep(5)
答案 0 :(得分:2)
您需要将PATHEXT
添加到
$ENV:PATHEXT += ";.py"
环境变量中。在PowerShell中,执行:
public void run() {
try {
while (true) {
byte[] buffer_rcv = new byte[1024];
DatagramPacket recvPacket = new DatagramPacket(buffer_rcv, buffer_rcv.length);
socket.receive(recvPacket);
System.out.println("get!!!");
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
LinkedList<Node> nodes = BDecode.bdecode_find_node(recvPacket);
for (Node n : nodes) {
table.add_node(n);
}
System.out.println("table size" + table.get_all_nodes().size());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
System.out.println("waiting new packet!!!!!!!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}