Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: What did I do wrong?  (Read 2964 times)

0 Members and 1 Guest are viewing this topic.

Dilbert

    Topic Starter
  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    What did I do wrong?
    « on: April 02, 2006, 06:47:39 PM »
    I have a bunch of joke programs on my computer (NAV doesn't like it, the old codger) and some are customizable with the command prompt. I'm writing a batch file to execute these programs with these special functions.

    Each time I input something into the prompt (namely, a program file) the program swears up and down the program doesn't exist. Why? What did I mess up at?

    Code: [Select]
    @ECHO OFF
    cls
    ECHO This batch file will simulate a bombed program. It will place it in the startup
    ECHO folder so it will run at next startup.
    :begin
    set choice=
    set /p choice=Choose program to bomb:

    IF EXIST %choice% GOTO create

    ECHO Sorry, the specified program does not exist.
    GOTO begin

    This is only a block; ":create" does exist in the file.
    "The geek shall inherit the Earth."

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: What did I do wrong?
    « Reply #1 on: April 02, 2006, 07:18:35 PM »
    The batch file looks reasonable. What exactly did you type at the prompt? Drive and pathname would required unless the bomb program exists in the current directory along with the batch file. The IF EXIST will not search the PATH as would a procedure call.

    Just my 2¢ worth.  8-)
    « Last Edit: April 02, 2006, 07:23:00 PM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Dilbert

      Topic Starter
    • Moderator


    • Egghead

    • Welcome to ComputerHope!
    • Thanked: 44
      Re: What did I do wrong?
      « Reply #2 on: April 02, 2006, 07:52:43 PM »
      I knew I was in C:\Utilities, so I typed in

      C:\Program Files\Opera\Opera.exe

      A quick check of my quick-launch shortcut shows the file does exist at that directory.
      "The geek shall inherit the Earth."

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: What did I do wrong?
      « Reply #3 on: April 02, 2006, 08:07:21 PM »
      With an embedded space in the path, you would need to quote your entry:

      "C:\Program Files\Opera\Opera.exe"

       8-)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Dilbert

        Topic Starter
      • Moderator


      • Egghead

      • Welcome to ComputerHope!
      • Thanked: 44
        Re: What did I do wrong?
        « Reply #4 on: April 02, 2006, 08:18:21 PM »
        Thank you. ;D

        I have one other issue. I want to create batch files with another batch file. I followed the code posted here but it didn't work.

        My full code:

        Code: [Select]
        @ECHO OFF
        cls
        ECHO This batch file will simulate a bombed program. It will place it in the startup
        ECHO folder so it will run at next startup.
        :begin
        set choice=
        set /p choice=Choose program to bomb:

        IF EXIST %choice% GOTO create

        ECHO Sorry, the specified program does not exist.
        GOTO begin

        :create
        REM - creates the batch file and writes it
        ECHO @echo off > bombtemp.bat
        ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ > bombtemp.bat
        ECHO @echo off > bombtemp2.bat
        ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ > bombtemp2.bat
        ECHO bomb.exe '%choice%' > bombtemp2.bat
        ECHO cd \utilities > bombtemp2.bat
        call bombtemp.bat
        del bombtemp.bat
        « Last Edit: April 02, 2006, 08:20:03 PM by Timothy_Bennett »
        "The geek shall inherit the Earth."

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: What did I do wrong?
        « Reply #5 on: April 03, 2006, 10:27:59 AM »
        You would need to use >> for all but the first line to be outputted. This will ensure you get a new copy of your batch file each time it runs and that the lines are appended to the file and not overwritten.

        I belive the link you provided made that point. ;)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: What did I do wrong?
        « Reply #6 on: April 03, 2006, 10:45:02 AM »
        Quote
        create
        REM - creates the batch file and writes it
        ECHO @echo off >> bombtemp.bat
        ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ > bombtemp.bat
        ECHO @echo off > bombtemp2.bat
        ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ > bombtemp2.bat
        ECHO bomb.exe '%choice%' >> bombtemp2.bat
        ECHO cd \utilities >> bombtemp2.bat
        call bombtemp.bat
        del bombtemp.bat

        You may have missed a few, also create needs a colon in front. I presume that bombtemp and bombtemp2 are meant to be two different files.

        Code: [Select]
        :create
        REM - creates the batch file and writes it
        ECHO @echo off > bombtemp.bat
        ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ >> bombtemp.bat
        ECHO @echo off > bombtemp2.bat
        ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat
        ECHO bomb.exe '%choice%' >> bombtemp2.bat
        ECHO cd \utilities >> bombtemp2.bat
        call bombtemp.bat
        del bombtemp.bat

         8-)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Dilbert

          Topic Starter
        • Moderator


        • Egghead

        • Welcome to ComputerHope!
        • Thanked: 44
          Re: What did I do wrong?
          « Reply #7 on: April 03, 2006, 10:52:56 AM »
          OK, I revised that code. My intention is as follows:

          Write a "bombtemp.bat" batch file, which includes instructions to create another batch file in the startup folder, which will execute the code.

          Ideally, I should have the following in the end:

          In C:\Utilities\bombtemp.bat:

          Code: [Select]
          cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\
          @echo off > bombtemp2.bat
          cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat
          bomb.exe '%choice%' >> bombtemp2.bat
          cd \utilities >> bombtemp2.bat

          In C:\Documents and Settings\Timothy\Start Menu\Programs\Startup\bombtemp2.bat:

          Code: [Select]
          @echo off
          cd \Documents and Settings\Timothy\Desktop\Desktop Games\
          bomb.exe '%choice%'
          cd \utilities

          And that's it. I used this batch file to achieve this:

          Code: [Select]
          @ECHO OFF
          cls
          ECHO This batch file will simulate a bombed program. It will place it in the startup
          ECHO folder so it will run at next startup.
          :begin
          set choice=
          set /p choice=Choose program to bomb:

          IF EXIST %choice% GOTO create

          ECHO Sorry, the specified program does not exist.
          GOTO begin

          :create
          REM - creates the batch file and writes it
          ECHO @echo off > bombtemp.bat
          ECHO cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\ >> bombtemp.bat
          ECHO @echo off > bombtemp2.bat >> bombtemp.bat
          ECHO cd \Documents and Settings\Timothy\Desktop\Desktop Games\ >> bombtemp2.bat >> bombtemp.bat
          ECHO bomb.exe '%choice%' >> bombtemp2.bat >> bombtemp.bat
          ECHO cd \utilities >> bombtemp2.bat >> bombtemp.bat
          call bombtemp.bat

          What I got was "bombtemp.bat" in the startup folder with this code:

          Code: [Select]
          @echo off
          cd \Documents and Settings\Timothy\Start Menu\Programs\Startup\
          @echo off
          cd \Documents and Settings\Timothy\Desktop\Desktop Games\
          bomb.exe '"C:\Program Files\Opera\Opera.exe"'
          cd \utilities

          What the heck did I do wrong?
          "The geek shall inherit the Earth."

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: What did I do wrong?
          « Reply #8 on: April 03, 2006, 11:06:23 AM »
          Somewhere along the way this seems to have changed. In any case you need to escape certain characters to pass them thru a redirection:

          ^> should pass a single > to the output file
          ^>^> should pass a double >> to the output file

          You just gotta love the brains that came up with this stuff. ;D
          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein