Console application called by bat file and passing parameter

I have a 2K3 server using the .NET 2.0 framework.

Issue I have is I cannot get the parameter passed into the app.

http://www.experts-exchange.com/Programming/Languages/.NET/Q_26582159.html
seemed promising until I tried it....the cmd window comes up with the name of the app and then "log" (which is my parameter).  Nothing executes...

I have tried 100 or so things and am getting tired of what should be so trivial I would think?

Please help me overcome this tiny obstacle as I can run the app itself and type the parameter and life is roses....just need to schedule a task to do it in a bat file.
LVL 1
cyimxtckAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
If your batch file is in the same dir as the EXE then this will let you run it regardless of whether the user runs it from a UNC path \\server\share, mapped drive or whatever.

@echo off
REM Change current directory to the [d]rive and [p]ath the batch file is in
pushd "%~dp0"

REM Run myprog.exe with any parameters that are passed to the batch file
myprog.exe %*
popd

Open in new window


@echo off
REM Change current directory to the [d]rive and [p]ath the batch file is in
pushd "%~dp0"
REM Run myprog.exe with hard coded into batch parameters
myprog.exe "Param1" "Param2"
popd

Open in new window


Can soon prompt for parameters too if wanted and check they are completed, e.g.

@echo off
REM Change current directory to the [d]rive and [p]ath the batch file is in
pushd "%~dp0"
REM Get parameters off user
set /p param1=Enter first parameter:  
set /p param2=Enter second parameter : 
if "%param1%"=="" (
  echo You must enter the first parameter
  exit /b
)
if "%param2%"=="" (
  echo You must enter the second parameter
  exit /b
)

REM Run myprog.exe with hard coded into batch parameters
myprog.exe "%param1%" "%param2%"
popd

Open in new window


Steve
0
Steve KnightIT ConsultancyCommented:
The bit about command window coming up with name of app and LOG try this from cmd prompt:

START "Myapp.exe log"

now try

START "" "Myapp.exe log"
or START "Title for the window" "Myapp.exe log"

Bizarre syntax of START command that gets us all sometimes, if you put the command line in quotes like if there are spaces in the name then it is treated as the Window title, which is the first parameter in quotes...
0
Bill PrewCommented:
Can you explain more about this:

I can run the app itself and type the parameter and life is roses.

How ecactly are you doing that? Do you start the EXE first, and then it prompts you for parms?  Or do you type in at a command line the EXE name, a space, and the parms?

~bp
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

cyimxtckAuthor Commented:
Haven't tried the other solution yet since I am on my phone but open the application exe file and then type in the parameter and it works.

Meaning the app works itself as expected
0
Bill PrewCommented:
So that sounds like the app is prompting you for the parms, rather than reading them from the command line, so that is a whole different problem.

Can you share the EXE or is it proprietary? Would be easier to test a proposed solution.

~bp
0
Steve KnightIT ConsultancyCommented:
Hmm good point,  well the options there are possible fiddles involving piping the data in to the app or sending keystrokes to it but better would be too change the app source add it is your anyway?

Would suggest read the command line and if no parameters them show your prompts for them if so.

Steve
0
cyimxtckAuthor Commented:
I have tried all the solutions above and nothing worked....it looks at the LOG parameter and says cannot find xyz.exe log.

It is proprietary so I cannot share the code or I would gladly do that.

sorry for the delay I have been flying all over the US.

Anything else you folks can think of to get that to work?

Please let me know.

Thanks,

B
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Try
   START "Title for the window" "Myapp.exe" "log"
   START "Title for the window" Myapp.exe log
As long as you do not have spaces in your path/exe or parameter name, you should see no difference between the both commands (but to those posted by Steve).
0
cyimxtckAuthor Commented:
That brings up the window but awaits input...If I then type LOG it works but it isn't getting passed in like a parameter?
0
cyimxtckAuthor Commented:
I am thinking it must be in the .NET app?

Here is a line of code I can share to make this more efficient:

    static void Main(string[] args)
    {
        try
        {
            String Action = Console.ReadLine().ToUpper();

if (Action == "LOG")
            {
                RWriter(xxx)
}
0
Steve KnightIT ConsultancyCommented:
If all else fails and frankly without seeing the app or even knowing if it is a gui, console or takes parameters etc. then AutoIt and similar you can use to watch for a window to appear then type / click options in there etc.

Could you give us a screen shot / video of you entering the app perhaps?
0
cyimxtckAuthor Commented:
Simply put buddy it is just an exe that you double click (or call from a bat file) and a DOS window appears.  From there you type log and it does it work.  There are other commands that you can type to get other functionality but it is just a DOS window.

No WPF or ASP.NET or...just a console app.
0
Steve KnightIT ConsultancyCommented:
Right, so if you open a command window, cd /d c:\whatever to get to the dir it is in then type

echo LOG | myapp.exe

does that do it?  After that the app won't be able to respond to any other key presses.

Possibly options "sendkeys" through vbscript, or like I said Autoit.

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cyimxtckAuthor Commented:
Command Not Recognized is what I get from that...

I will have to look at Autoit and see what I can come up with.

Thanks for the input
0
Steve KnightIT ConsultancyCommented:
It really would help us to help you if you helped us with info!

command not recognised would be referring to the fact you aren't in the directory containing your myapp.exe application.

A screeshot really helps with such things.

Good luck with it.
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The code snippet you posted tells exactly that LOG needs to be entered manually (via console input), and cannot be provided as a parameter. If, however, you see string[] args used somewhere in the main procedure then you'll have to look at that code part for the parameters allowed. The code would have to be executed prior to the ReadLine.

With what we know and can see, simulated input (SendKey, AutoIt) seems to be the only option - if the echo LOG does not work, which it should.
0
cyimxtckAuthor Commented:
So is this the appropriate syntax for the echo?

echo LOG | myapp.exe

Thanks,

B
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Yes, if executed in the folder the app is in. Otherwise you'll have to use something like
  echo LOG | C:\Path\To\App\myapp.exe
or
   cd /d C:\Path\To\App
   echo LOG | myapp.exe
0
Steve KnightIT ConsultancyCommented:
Yes, as I said in http:#a40868623

Do give it a try as Qlemo or I posted first as long as you don't need to interact with the app. afterwards as it should work.  The errors gave were just sounding like you hadn't gone into the directory where the app is as I said.

Steve
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I might have said it more clear, but Steve told first in http:#a40868623, so he should get points too. If you agree, one of us (both being Topic Advisors) can open the question again.
0
cyimxtckAuthor Commented:
I do agree after re-reading this.  Please adjust it accordingly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.