Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file & Shell

Status
Not open for further replies.

Anesthaesia

Technical User
Aug 30, 2001
126
GB
Hi All,

I have a .bat file which I am executing using a Shell command. However, when I execute it using Shell the commands in the batch file are not executed - if I run the bat directly it works fine. Any ideas why this is?

It's a very simple file which changes directories then executes an exe (folder needs to be selected as exe is path dependant) What seems to be happening is the change directory commands are not taking effect (limited logging points to this as being the problem)

The lines are

E:
cd demo\reports
"e:\demo\demo.exe"

As I said, when executing the bat file on it's own it does wnat it's supposed to...

Cheers,
D
 
Show me the shell statement that you are using to execute the bat file.

Maybe this world is another planet’s Hell.
 
While in the ide the app.path = C:\Program Files\Microsoft Visual Studio\VB98 not where you think it is.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
The app path already exists (not default program files folder).

When using the shell command the command window briefly flashes and definately executes - I have output the error to a log file using "> c:\error.log" in the batch file and this file is created and contains the info it should.

It definately seems that the change directory part of the batch file is not working when using the shell command, but works fine when the bat is executed directly.
 
Thanks for the replies guys - I seem to have found a solution in another post (not the same problem, but code helped)

Using the code below to set the currentdirectory, the batch file now executes without problems.

Searching through all posts one by one containing "batch file" eventually paid of...

Cheers,
D

Code:
Option Explicit

Dim oWsh:Set oWsh = CreateObject("WScript.Shell")
oWsh.CurrentDirectory = "F:\Dir"
oWsh.Run "FileName.exe", 0, True
 
Just to clarify drjavajoe's point, since it comes up often: app.path often isn't the same value in the compiled version as it is in the development version. In the former, it's where your exe file resides; in the latter, it's where your vbp file resides. Maybe that wasn't the problem here, but I can't tell conclusively from the posts that it wasn't.

Bob
 
Hi wondering if you could help on the shell command

I currently use this command to open the database

Code:
retval = Shell("c:\program files\microsoft office\office\msaccess.exe t:\EAD\ead.mdb")
[\code]

I would like to run a macro on the shell line if possible. I do not want to use the autoexec macro.

Thank you for responses

Chris
 
found the answer on the shell command just add a forward slash and then a x and the macro name.

e.g
Code:
retval = Shell("c:\program files\microsoft office\office\msaccess.exe t:\EAD\ead.mdb /x runtables")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top