Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

cmd prompt help

Options
  • 25-06-2007 3:34pm
    #1
    Registered Users Posts: 11,038 ✭✭✭✭


    Hey, I have to type the same couple of lines in a command prompt couple of times a day, isn't there a way of making a text file that you can run instead or something? Like a shell script or something (??)


Comments

  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    dulpit wrote:
    Hey, I have to type the same couple of lines in a command prompt couple of times a day, isn't there a way of making a text file that you can run instead or something? Like a shell script or something (??)

    You are looking for a batch file. Create it in notepad or something, put the commands into the file and save it with a .BAT extension.


  • Registered Users Posts: 11,038 ✭✭✭✭dulpit


    tom dunne wrote:
    You are looking for a batch file. Create it in notepad or something, put the commands into the file and save it with a .BAT extension.

    That's it exactly... Having a bit of a dumb day, should have known that...:o


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Sort of a follow up question - I proably should start a new string and will do if that's what needed. I have a batch script that's been working on an old machine here in the office for the last two years. The machine is on it's last legs and needs replacing (it's 8 years old and running win98se) so I moved the scripts to a newer machine (dual core winxp pro machine < 6months old) and the scripts don't run. There's nothing wrong with the code: I've checked each dos command on a cmd window and they each of them work fine. They also, inputted manually, work in sequence. But when I run the batch script it runs the first command and then exits. Any ideas? Is it because xp doesn't really have DOS just has a DOS emulator or am I doing something really dumb?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Permissions are probably the issue.

    Edit the script so that it echos everything to screen, you should then be able to see what's going wrong - just remove "@echo off" from the top of the script.


  • Registered Users Posts: 1,193 ✭✭✭liamo


    In addition to Seamus' suggestion, put a "pause" command after each command in the batch file so that you can easily read the output/result of each command.


  • Advertisement
  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    Or even better, post up the script here.


  • Closed Accounts Posts: 890 ✭✭✭patrickolee


    It's probably a path error and you aren't seeing it as the thing is running and failing so quickly. As previous poster says, put in pause commands after each command so you can see what's failing


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    Hi guys, the script is for a night time admin person with very little it experience. It is to allow him to upload a file to a web server without needing him to know much about FTP. He basically hits a button. Anyways here's the code (works fine in win98)
    c:\
    cd\
    cd progra~1
    cd intern~1
    iexplore c:\countdown.html
    cd\
    c:\download_script.bat
    exit
    

    download_script.bat
    cd\
    cd progra~1
    cd ipswitch
    cd ws_ftp~2
    ftpscrpt -f c:\john_download_test.scp
    

    Sorry that's the code for another admin person who has to download the file in the evening (as a backup)
    Here is the upload code (it's pretty much identical)
    h:\
    cd\
    copy nova_be.mdb h:\backup\nova_be.mdb
    c:\
    cd\
    cd progra~1
    cd intern~1
    iexplore c:\countup.html
    cd\
    c:\upload_script.bat
    exit
    

    upload_script.bat
    cd\
    cd progra~1
    cd ipswitch
    cd ws_ftp~2
    ftpscrpt -f c:\paddy_upload_test.scp
    


    Each of these commands works without issue if manually entered into a command prompt window. It's only when the batch script is called that I experience problems. Thanks for your help and sorry if I'm missing something stupid.

    -RD


  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    It's only when the batch script is called that I experience problems. Thanks for your help and sorry if I'm missing something stupid.

    -RD

    What problems are you experiencing? Exact details, steps, errors, please.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    It may be a good idea to update the code a little for 2000/XP and get rid of some lines.
    This can be replaced with less lines :)
    h:\
    cd\
    copy nova_be.mdb h:\backup\nova_be.mdb
    c:\
    cd\
    cd progra~1
    cd intern~1
    iexplore c:\countup.html
    cd\
    c:\upload_script.bat
    exit
    

    Use this instead:
    REM This assumes that the H:\ drive is available. If a user isn't logged on, the H:\ may not be there. 
    REM The "/Y" switch forces an overwrite if the file in the destination already exists
    copy /Y h:\nova_be.mdb h:\backup\
    
    REM The "start" command is a command to the OS to open the file using the default handler. It returns control to the prompt after launching.
    REM If you specifically need to open IE, then use "C:\Program Files\Internet Explorer\iexplore.exe" instead (including the double-quotes).
    start c:\countup.html
    
    c:\upload_script.bat
    

    This can be replaced with just one line :)
    cd\
    cd progra~1
    cd ipswitch
    cd ws_ftp~2
    ftpscrpt -f c:\paddy_upload_test.scp
    

    Use this instead:
    REM I'm assuming that WS FTP is installed at C:\program files\ipswitch\WS_FTP Professional
    "C:\program files\ipswitch\WS_FTP Professional\ftpscrpt.exe" -f "c:\paddy_upload_test.scp"
    

    Give that a go and let me know how you get on. In reality, they're not doing a whole lot different than just making the scripts easier to read, but there are one or two items in there that I know XP would baulk at.


  • Advertisement
  • Closed Accounts Posts: 97 ✭✭koloughlin


    Well one thing that looks suspect is the syntax to change drives.
    c:\
    
    may change to the c: drive in win 98, but it won't work in later versions of windows. Drop the trailing backslash and just leave it as
    c:
    

    I tried in in 2000, XP and 2003 and it fails in all of those.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Just an example of the first one only.
    @echo off
    
    setlocal 
    
    pushd c:
    pushd c:\progra~1\intern~1
    iexplore c:\countdown.html
    
    popd 
    
    call download_script.bat
    
    popd 
    endlocal
    

    Just explain each one.

    pushd + popd

    these allow you to change directory/drives while remembering where you last where. A pushd will change directory and remember and a popd will return the location to prior to the last pushd.

    setlocal + endlocal

    you should always use these. It basically keeps a backup of the environment variables in case you make a mess of them or need to change loads of things that are liable to break other stuff once the batch file has completed.

    call

    Always use call to run a batch file within a batch file. That way it will return to that batch file to continue on. Without it the batch file running will ignore the previous one.


Advertisement