BleepingComputer.com: Batch File

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch File Not as simple as I thought :(

#1 User is offline   danbrownlow 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 99
  • Joined: 05-March 07
  • Gender:Male

Posted 22 October 2007 - 10:33 AM

Hello all, I have a little problem. I use java and javac alot and everytime I open "cmd" I have to cd to the right directory! Which can be a pain.

Well, I thought I'd make a .bat file so that when I click and open it, it would be in the right directory. I went into Notepad and typed:
cd c:\Users\<username>\Documents\Java

and saved it as a .bat file, however, when I run it, it comes up quickly and then dissapears! I tried adding pause to the end, but that was no help.
Can anyone offer any ideas?
Thanks :D

#2 Guest_uhaligani_*

  • Group: Guests

Posted 22 October 2007 - 12:22 PM

You will need to write the path to where the .bat file is situated.
eg The default for the command prompt is c:\users\username. so the easiest thing would be to place the bat file in that folder.

#3 User is offline   danbrownlow 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 99
  • Joined: 05-March 07
  • Gender:Male

Posted 22 October 2007 - 12:35 PM

It does exactly the same thing, when I start the bat file, it loads and dissapears. I wanted it to automatically change the directory so I wouldn't need to manually type it in everytime I want to compile or run a java file.
Anyone got any more ideas?

#4 User is offline   usasma 

  • Still visually handicapped, new avatar (a camel) :0)
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 16,690
  • Joined: 02-October 05
  • Gender:Male
  • Location:Southeastern CT, USA

Posted 22 October 2007 - 06:15 PM

Do you run the .bat file in the cmd window? If not, then it'll just terminate when it's done. The /f switch will prevent the command prompt from closing, but I'm not familiar enough with the syntax to figure out how to do it.
- John
**If you need a more detailed explanation, please ask for it. I have the Knack. **

#5 Guest_uhaligani_*

  • Group: Guests

Posted 23 October 2007 - 04:50 AM

Your syntax is corrct. I've tried every combination and it works for me. I called the bat "try" (but the name is of no significance!) I saved it to my user, which in my case is "Administrator" (I run as the "power" administrator, without a user). For the exercise I created the Folder "java". Every time it changed to that directory.
Have you tried right clicking the Command prompt and running as the Administrator, thats all I can think of?

#6 User is offline   frankblourtango 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 63
  • Joined: 26-September 07
  • Gender:Male
  • Location:philly

Posted 23 October 2007 - 10:33 AM

Does it give you any error if you open a dos prompt and then run it? See if it completes without any errors and returns to the prompt. I test my batches by doing that and watching them complete. Just my two cents.

#7 User is offline   danbrownlow 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 99
  • Joined: 05-March 07
  • Gender:Male

Posted 23 October 2007 - 11:24 AM

Yea' it runs fine when I open it via CMD by typing 'java.bat', I kind of was wondering how I could get it to run by just clicking the link file in Explorer, as I am quite lazy. Thanks for the help anyway, it works fine in CMD so thank you =]

#8 Guest_uhaligani_*

  • Group: Guests

Posted 24 October 2007 - 12:42 AM

I think I misunderstood your intention. I thought you were concerned with the command prompt. If you want to open Windows explorer to your Java folder, then you should open another instance of explorer on your desktop or shortcut menu. right click and in the properties , after C:\Windows\explorer.exe make a space and then C:\Users\<username>\Documents\Java. Is that what you are looking for?

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users