Click here to Skip to main content
15,512,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 22-May-21 18:33pm
v2

C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM Input_FileName
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();
 
Share this answer
 
In MS-DOS eara, it used to be:
C:
CD C:\Directory\PROGRAM.exe\Subdirectory\
PROGRAM <Input_FileName

assuming standard io is used.
 
Share this answer
 
Comments
Member 13813026 5-May-18 11:47am    
Neither solution works, must be an io issue. The compiled program is written in FORTRAN. It executes from a DOS command prompt - once you navigate to the working directory, enter the executable name and it runs. The executable pauses to await the filename from the DOS prompt.

All that my batch file does is opens the cmd console and enters the executable filename. I then enter the filename. Runs fine, but still clunky.

Pls understand you are interacting with a materials scientist/engineer - not IT trained. I go back to the era of submitting IBM cards to be interpreted by a card reader - if the card reader did not chew up the cards. I took one course in FORTRAN, I was already self-taught in FORTRAN, I took the course to learn the job control language (CDC mainframe). Also self-taught in VB6.

Thanks again for guidance.
If you need input interaction in your bat file, use:
   Set /p "variable_name=some string in screen: "

@echo off

setlocal 
cd /d "C:\Program Files (x86)\Program Name\Bin\"

:loop

cls & echo\
set "program=" & set "next=" & (
     set /p "program=Plz, Input File Name: " 
    ) || goto :loop

echo\ 
if exist "%cd%\%program%" (
      <con: call "%program%"
    ) else timeout -1 | (
	        echo\- Input ERROR
	        echo\- "%program%" do not exist!
	     ) 
	)

echo+[1] Run again/another one:
echo+[2] Exit/Stop this script:

echo\
set /p "next=What you will choose? "
if %next% equ 1 goto :loop

endlocal & goto :eof


Obs.: This not help you:

   C:
   cd C:\Directory\PROGRAM.exe\Subdirectory\


Use: CheckDirectory | + go to /Drive "D:\Path" | + "in double-quotes"
   cd /d "C:\Directory\PROGRAM.exe\Subdirectory\"
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900