Batch file doesn't process parameter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
avalancha
Posts: 8
Joined: 25 Mar 2010 03:57
Location: Stuttgart - Germany

Batch file doesn't process parameter

#1 Post by avalancha » 25 Mar 2010 04:26

Hey out there!

I have a quiestion concerning a .bat of mine and I hope this is the right spot to post it:

My task is the following: I need to write a batch that starts an Access database and processes a parameter to it so that a module I created can catch it as the following:

Code: Select all

If Command = "test" Then


But the batch has to work with relative paths and that's where the problems come in: it all works fine like this:

Code: Select all

"C:\Program Files\Microsoft Office\Office11\Msaccess.exe" "C:\Program Files\Subdirectory\business.mdb" /cmd "orders"


but as soon as i try it like that:

Code: Select all

".\business.mdb" /cmd "orders"


the database opens up (it's always in the same folder) but the parameter is not processed and the module does not work!

I really need help here, thanks in advance!!

Best regards,
Patrick

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file doesn't process parameter

#2 Post by aGerman » 25 Mar 2010 11:44

Try this

Code: Select all

start "" "msaccess.exe" "%~dp0business.mdb" /cmd "orders"

or

Code: Select all

start "" "msaccess.exe" "%cd%\business.mdb" /cmd "orders"


The option /wait means that your batch will not continue until you close Access.

Code: Select all

start "" /wait "msaccess.exe" "%cd%\business.mdb" /cmd "orders"


Regards
aGerman

avalancha
Posts: 8
Joined: 25 Mar 2010 03:57
Location: Stuttgart - Germany

Re: Batch file doesn't process parameter

#3 Post by avalancha » 25 Mar 2010 12:25

yea I knew "/wait" before but hey:
oh... my... god
you are the BEST!!!! It works!!

Du kannst dir nicht vorstellen was für einen Gefallen du mir grade getan hast und wie viele Tage Rumgemurkse damit zu Ende gehen! DANKE!

Best regards,
Patrick

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file doesn't process parameter

#4 Post by aGerman » 25 Mar 2010 13:13

You're welcome.
For your understanding:
The dot (.\) is only relative to your batch file, but not to msaccess.exe. It needs the entire path.
Because /cmd is a switch of msaccess.exe you can't use it only with the .mdb file.

Grüße aus Thüringen nach Baden-Württemberg :wink:

avalancha
Posts: 8
Joined: 25 Mar 2010 03:57
Location: Stuttgart - Germany

Re: Batch file doesn't process parameter

#5 Post by avalancha » 25 Mar 2010 14:16

ok well talking already about understanding... so what does the

Code: Select all

%~dp0
mean?
"Look in the same folder" or something similar?

Greetings my friend :mrgreen:

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file doesn't process parameter

#6 Post by aGerman » 25 Mar 2010 14:34

Well, I'm sure that you know parameters like %1, %2 etc.
%0 is a special kind of parameter and contains the "own call" of the batch file (means something like the full name). You can use options for this parameters, so the d is for drive and the p is for path. All in all %~dp0 returns drive and path of your batch file. For all those options have a look to the help of call (call /?).
%cd% is similar, but not the same. It contains the current working directory of your batch file, but this can be changed using CD or PUSHD / POPD commands.

Hope this will clarify some more, my friend :lol:

avalancha
Posts: 8
Joined: 25 Mar 2010 03:57
Location: Stuttgart - Germany

Re: Batch file doesn't process parameter

#7 Post by avalancha » 26 Mar 2010 00:56

Jep, sure did.
You know, I'm rather a C programmer and quite new to this stuff... I had never heard about this parameter before, therefore again: tanks

Patrick

Post Reply