将输入文件名从批处理文件传递到dos(cmd)提示符? [英] Pass an input file name to a dos (cmd) prompt from a batch file ?
问题描述
这是启动程序并提示用户输入的批处理文件(在可执行文件中硬编码)
C:
CD C:\Directory \ PROGRAM.exe \Subdirectory \
PROGRAM
cmd控制台打开并暂停用户输入输入文件名。
我尝试过:
我试过了
C:
CD C:\Directory\PROGRAM.exe \Subdirectory \
PROGRAM Input_FileName
和
C:
CD C :\Directory \ PROGRAM.exe \Subdirectory \
PROGRAM
Input_FileName
显然,我不明白如何将文件名传递给命令提示符(如果可能),因为我不理解批处理文件和命令控制台中命令提示符之间的语法(交互)。
如果是p可以根据需要传递文件名,然后我想学习如何在批处理文件中为多次运行创建循环 - 多个输入文件。
谢谢。
Here is the batch file that launches the program and prompts the user for input (hard coded within executable)
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM
The cmd console opens and pauses for user input of the input file name.
What I have tried:
I have tried
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM Input_FileName
and
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM
Input_FileName
Clearly, I don't understand how to pass the filename to the command prompt (if that's possible) because I don't understand the "syntax" (interaction) between the batch file and the command prompt in the command console.
If it is possible to pass a filename as desired, I would then like to learn how to create a loop in the batch file for multiple runs - multiple input files.
Thank-you.
推荐答案
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM Input_FileName
这样做会很好 - 但是你传递给它的程序必须查找参数。如果没有 - 什么都不会发生。
如何在代码中查找它们取决于您编写的应用程序类型:对于控制台应用程序,参数通过<$ c传入$ c> main 方法作为字符串数组 arv
。对于WinForms应用程序,可以通过Environment类访问它们:
Will do it fine - but the program you pass it to has to look for the parameters. If it doesn't - nothing will happen.
How you look for them in your code depends on what kind of app you write: for a Console application, the parameters are passed in via the main
method as the array of strings arv
. For a WinForms app, they are accessed via the Environment class:
string[] args = Environment.GetCommandLineArgs();
在MS-DOS eara中,它曾经是:
In MS-DOS eara, it used to be:
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM <Input_FileName
假设使用标准io。
assuming standard io is used.
这篇关于将输入文件名从批处理文件传递到dos(cmd)提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!