Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Creating Batch Files

  1. Nov 12, 2003 #1
    Hi guys,

    I am trying to create a batch file to help automate me creating dvi and pdf files from tex files. I'm in a windows xp environment. I have set up a batch file that asks the user whether they want to create a pdf file or a dvi file for output and then opens the command line editor:

    Code (Text):

    @echo off
    @title Create dvi-pdf Files
    @set /p type=dvi or pdf?:
    echo Type: texify --clear --src [Filename]
    At present I'm not doing anything with the information the user has given me, but I will. At present I just want to know how to add information to the prompt. At present all it does is open up the command prompt to the current directory, I want it to then write information to the prompt and execute it. Like so:

    The command prompt opens like I said:
    Code (Text):

    Then the batch file writes to the prompt:
    Code (Text):

    C:\Temp\texify --clear --src Temp.tex
    Which will then convert the tex file into a dvi file and clear all the other files such as the aux file and log file. How do I get the batch file to write to the prompt?
  2. jcsd
  3. Nov 12, 2003 #2


    User Avatar
    Staff Emeritus

    Last edited by a moderator: Apr 20, 2017
  4. Nov 12, 2003 #3
    Thanx dduardo,

    I had already found that link though. I have made progress. The batch file asks the user for the name of the file and whether they want pdf or dvi putput, then they are taken to the command prompt witht the current path displayed, all they then have to do is type in the variable name for the output and away it goes!

    It's actually more labour intensive to run the batch file than to typw it in directly. But I know this will work eventuially.

    I have put a link to the batch file in the context menu for any tex file, so that is good. However it makes asking for the filename stupid really, but I can't work out how to let the batch file know which file they clicked on.

    I still can't get the batch file to automatically run the thing either, it seems silly that I have to type a variable name into the command promt to run it.
  5. Nov 12, 2003 #4


    User Avatar
    Science Advisor
    Homework Helper

    I'm not sure about windows, but you could try
    cmd32.exe %foo
    where foo is the variable you want to use.

    If you want to execute a command, just have the batch file call it directly.
  6. Nov 12, 2003 #5
    I just discovered the pipe command "|" which uses the output of one command as the iput of another. Just what I needed to make the batch file work automatically once I've given it data. =]

    So now all I do is input the file name and output type, and away it goes. Now all I need to do is work out how I can find out the filename automatically, after all I am clicking the context menu of a particlular file.
  7. Nov 13, 2003 #6
    Well, I can't work out how to find the identity of the file that was clicked. I know there must be a way, but I can't seee it yet. Anyone have any ideas at all?
  8. Nov 13, 2003 #7


    User Avatar
    Science Advisor
    Homework Helper

    You can set the filename to be passed as an argument as part of the default action as part of the set up in file types.
  9. Nov 15, 2003 #8
    Okay, that half works. It correctly passes the filename to the batch file, the problem is that it sends the entire path, eg.

    "C:\My Documents\Test.tex"

    I want it simply to send "Test.tex" as the filename. Can I force the DDE to send only the local filename? Or if not is there a way to have the batch file erase the earlier path, which I know in advance because I keep all my tex files in the one directory?
  10. Nov 16, 2003 #9


    User Avatar
    Science Advisor
    Homework Helper

    I'm not sure.

    If you were using Unix, I'd recommend having the script strip out the pathname using sed or perl. You can probably do something similar.
  11. Nov 16, 2003 #10
    Yeah, I'm starting to see the benefits of linux. I always new it was useful, as we use it at uni. But now I'm seeing the beneifts for everyday use as well.

    I'm sure there us a way to write up a simple c++ exe or dll to take the file type and append it as necessary, just need to work out how to send the info in the batch file to the exe and then back to the batch file.
  12. Nov 16, 2003 #11
    Okay, problem completely solved.

    I found some new commands I didn't know about, that allow you to pick out the useful bits of the file path.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook