My program breaks when run with batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
smithi
Posts: 2
Joined: 12 Dec 2011 19:15

My program breaks when run with batch

#1 Post by smithi » 12 Dec 2011 19:21

Trying to run a simple program I created in batch. The program uses a relative hard-coded file-path within itself to access data files within the program directory.
When I run my program by double clicking on it, it works fine.
If I run my program with batch, my error pops up saying it can't find the relative data file any more.

Batch code:

Code: Select all

@echo off
start "Reminders" "%~dp0Reminders\Bin\Reminders.exe"


I also output the relative file-path for the data file if it can not be found, and it is correct.

So what could be causing my program to not be able to find the data file when run with batch?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: My program breaks when run with batch

#2 Post by orange_batch » 12 Dec 2011 20:21

The only problem could be that it's working in the wrong directory. So that means it's being passed along by command prompt to your program. Either reset it explicitly within your program, or change the current directory of Command Prompt first.

You can accomplish this while keeping your paths relative.

Code: Select all

@echo off
pushd "%~dp0Reminders\Bin"
start "Reminders" "%~dp0Reminders\Bin\Reminders.exe"
popd

Or simply...

Code: Select all

@echo off
pushd "%~dp0Reminders\Bin"
start "Reminders" "Reminders.exe"
popd

Let me know if it works.

smithi
Posts: 2
Joined: 12 Dec 2011 19:15

Re: My program breaks when run with batch

#3 Post by smithi » 12 Dec 2011 20:35

That works tyvm

Post Reply