通过带有参数的程序运行文件 [英] Running file through a program with arguments

查看:62
本文介绍了通过带有参数的程序运行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我似乎无法通过程序传递参数.我不知道如何清楚地解释它,但是在这里:

My issue here is that I can't seem to pass arguments through my program. I'm not sure how to explain it clearly but here it goes:

我希望能够通过带有参数的自定义解释器运行脚本文件.

I want to be able to run a script file through a custom interpreter with arguments.

例如:

AtomScript.exe main.atom->程序运行

当我想通过批处理文件运行它时:

When I want to run it through a batch file:

main.atom->程序运行

现在,当我想使用批处理文件中的AtomScript命令通过程序传递参数时:

Now when I want to pass arguments through the program using the AtomScript command in a batch file:

AtomScript.exe main.atom arg1 arg2->程序运行时带有参数

参数已传递.但是,当我想使用简单的main.atom命令来运行带有参数的命令时,它将不起作用:

The arguments are passed. But when I want to use the simple main.atom command to run it with arguments it doesn't work:

main.atom arg1 arg2->程序不带参数运行

我现在不知道该怎么办.有什么建议吗?

I'm not sure what to do at this point. Any suggestions?

推荐答案

main.atom 不是可执行文件,因此不能接受任何参数

main.atom is not an executable, so it can't take any parameters

Windows知道必须启动哪个程序,并且这样做(忽略任何参数)

Windows knows, which program has to be started and does so (ignoring any parameters)

只有直接启动可执行文件,才可以定义参数(第一个是 main.atom )

Only if you start the executable directly, you can define parameters (the first one being main.atom)

例如:

C:\>assoc .txt
.txt=txtfile

C:\>ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1

assoc 定义扩展名是什么文件类型("txtfile")

assoc defines, what filetype that extension is ("txtfile")

ftype 定义了对此文件类型必须执行的操作(启动记事本)

ftype defines, what has to be done for this filetype (start notepad)

您会看到,只有一个参数%1 (文件名( main.atom )).当然,您可以使用更多参数来扩展它(需要以管理员身份运行):

You can see, there is just one parameter %1 (the filename (main.atom)). Of course you could expand it with more parameters (needs to be run as administrator):

ftype txtfile=%SystemRoot%\system32\NOTEPAD.EXE %*

(在此示例中没有多大意义),但我不建议这样做(仅在您的计算机上完成).最好使用官方方式":批处理文件中的操作与命令行上的操作完全相同:使用所需参数启动可执行文件:

(which makes not much sense with this example), but I don't recommend it (it's just done on your computer). Better use the "official way": in the batchfile do exactly the same as on the commandline: start the executable with the desired parameters:

AtomScript.exe main.atom arg1 arg2    

这篇关于通过带有参数的程序运行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆