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

Author Topic: luanch of executable from within .bat file fails  (Read 18177 times)

0 Members and 1 Guest are viewing this topic.

Jerry Ford

    Topic Starter


    Rookie

    • Experience: Expert
    • OS: Windows 7
    luanch of executable from within .bat file fails
    « on: November 21, 2014, 06:49:26 PM »
    I am trying to get started with Google's Android Studio. I have installed the studio software and the Android SDK on my d:\ drive, as follows...

    d:\dev\android\android-studio
    d:\dev\android\sdk

    In the SDK, there is a .bat file, android.bat, that in turn calls another .bat file, find_java.bat.

    When I run android.bat, it fails to launch the second file...

    d:\dev\android\sdk\tools>android
    '"d:\dev\android\sdk\tools\lib\\find_java.bat" -s' is not recognized as an internal or external command,
    operable program or batch file.

    The following command entered on the command line does in fact run the find_java.bat file...

    d:\dev\android\sdk\tools\lib\\find_java.bat -s

    ...but the find_java.bat file cannot be found from within the android.bat file.

    I have sought help from Google, and the engineer assigned to the problem reports that when he runs android.bat on his machine, it works fine.

    Any suggestions as to why the same .bat file works on the Google machine and not on mine?

    The Google OS is Windows 7 Home Premium x64, mine is Windows 7 Ultimate x64.

    Thanks.

    Jerry

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: luanch of executable from within .bat file fails
    « Reply #1 on: November 21, 2014, 07:30:35 PM »
    Well, the two commands are not the same.
    Please copy and paste the command so we can see it.

    The -s must come right after the find command.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: luanch of executable from within .bat file fails
    « Reply #2 on: November 21, 2014, 10:10:16 PM »
    Would probably help to see the contents of each batch file.

    Jerry Ford

      Topic Starter


      Rookie

      • Experience: Expert
      • OS: Windows 7
      Re: luanch of executable from within .bat file fails
      « Reply #3 on: November 24, 2014, 05:59:11 PM »
      Sorry if I was not precise in my initial description of the problem. I was trying to keep my discussion brief.  But it's a complicated situation that, I guess, requires more verbiage.

      When I install the Android SDK, the installer offers to run the SDK Manager at the conclusion of the installation.  I say yes, and I get the following error message...

      Failed to execute tools\android.bat:
      The system cannot find the file specified.

      But I have already set an Environment Variable, ANDROID_SDK_HOME, to d:\dev\android\sdk and added that variable to my PATH, so I expect there to be no problem reaching tools\android.bat from anywhere on the system. 

      When I open a command window and cd to the SDK directory and run android.bat manually, I get this...

      D:\dev\android\sdk\tools>android
      '"D:\dev\android\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command,
      operable program or batch file.

      There is now a problem running another file, find_java.exe, in the tools\lib folder. 

      Actually, android.bat runs lib\find_java.bat, which in turn attempts, and fails, to run find_java.exe, with this command...

      for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a

      And yet, if I go to the tools directory in a command window and enter that exact same command that just failed, it does in fact run...

      D:\dev\android\sdk\tools>lib\find_java.exe -s
      C:\PROGRA~3\Oracle\Java\javapath\java.exe
      D:\dev\android\sdk\tools>

      (And yes, I have tried it with and without the double quotes, and with and without the double slash in the path. Nothing works.)

      The batch files, BTW, appear to be correct, with no broken syntax.  These files do run on other systems.  In fact, as a test, I installed the SDK on my wife's machine and the batch files all work fine.  The difference:  My machine, where they don't work, runs Windows 7 Ultimate, my wife's machine runs Windows 7 Home Professional.  (And no, using my wife's machine for Android development is not an option. I need to make it work on mine.)

      Thanks.

      Jerry

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: luanch of executable from within .bat file fails
      « Reply #4 on: November 25, 2014, 06:23:13 AM »
      I get the following error message...

      Failed to execute tools\android.bat:
      The system cannot find the file specified.

      The message shows a relative path is being used.



      Jerry Ford

        Topic Starter


        Rookie

        • Experience: Expert
        • OS: Windows 7
        Re: luanch of executable from within .bat file fails
        « Reply #5 on: November 25, 2014, 01:35:51 PM »
        foxidrive:

        Yes, a relative path.  That particular error message is displayed when SDK Manager.exe runs. That .exe is in the sdk folder, android .bat is in the sdk\tools folder, so the .bat file is in the tools folder relative to the exe.

        But it makes no difference how I initiate the process, something is preventing the android tools from traversing the Windows path. 

        Again, these files do all work on some systems.  I'm pretty sure it is not a coding error in the various .exe/.bat files. My current best guess is there is a permission conflict.  I just don't know what permissions, where to find them, and how to fix the problem.  I've looked at the security settings in various Windows peroperty dialogs for the files and folders, nothing works. 

        Except it does work, on other people's Windows machines.  Just not on mine.

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: luanch of executable from within .bat file fails
        « Reply #6 on: November 25, 2014, 01:54:02 PM »
        Do you get a UAC prompt when running the installer?

        What are the user account control settings for the computers that it works on and your computer?

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: luanch of executable from within .bat file fails
        « Reply #7 on: November 25, 2014, 01:58:45 PM »
        From the Android Developer Website.
        Quote
        On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.
        Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.7.0_21.

        Jerry Ford

          Topic Starter


          Rookie

          • Experience: Expert
          • OS: Windows 7
          Re: luanch of executable from within .bat file fails
          « Reply #8 on: November 25, 2014, 06:56:09 PM »
          squashman:

          JAVA_HOME has been set on my system for a long time prior to trying to use Android, and it remains pointed at a valid JDK.

          Jerry

          Jerry Ford

            Topic Starter


            Rookie

            • Experience: Expert
            • OS: Windows 7
            Re: luanch of executable from within .bat file fails
            « Reply #9 on: November 25, 2014, 10:42:28 PM »
            squashman:

            If I run the installer as administrator, I get the prompt.  If not, no prompt. Either way, makes no difference, files still don't run correctly.

            User account control properties are the same on both computers (mine, Windows 7 Ultimate, where the SDK files don't work, and my wife's, Windows 7 Home Pro, where the SDK files do work)...

            Default - Notify me only when programs try to make changes to my computer.

            Something I had not noticed before, but in the SDK installer .exe's properties dialog, there is this message at the bottom...

            Security - This file came from another comptuer and might be clocked to help protect the computer.

            When I click the [ Unblock ] button, the text goes grey (and is not shown on subsequent openings of the properties dialog), but it makes no difference, the executables still do not work correctly.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: luanch of executable from within .bat file fails
            « Reply #10 on: November 26, 2014, 12:35:06 PM »
            The batch files, BTW, appear to be correct, with no broken syntax.

            Your question is sorta like saying:  "I wrote some source code and it doesn't work - can you tell me what's wrong with it?" and you don't show anyone the source code.

            Code: [Select]
            for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
            On a casual examination, the code above will only work if the find_java.exe is in the same folder as the batch file.

            patio

            • Moderator


            • Genius
            • Maud' Dib
            • Thanked: 1769
              • Yes
            • Experience: Beginner
            • OS: Windows 7
            Re: luanch of executable from within .bat file fails
            « Reply #11 on: November 26, 2014, 02:09:18 PM »
            Would probably help to see the contents of each batch file.

            This says it all...
            " Anyone who goes to a psychiatrist should have his head examined. "

            Jerry Ford

              Topic Starter


              Rookie

              • Experience: Expert
              • OS: Windows 7
              Re: luanch of executable from within .bat file fails
              « Reply #12 on: November 26, 2014, 03:01:16 PM »
              Okay, here are the two files where it starts. There are more, but I can't copy the whole SDK.  It is a free download though, if you really want to purse all files involved. Get it here (you'll need to create an account, but,again, free)...

              https://developer.android.com/sdk/index.html?hl=i

              The SDK comes in an executable installer.  When I run it (with or without administrative privileges, doesn't seem to matter, and it worked fine without on the Win7 Home machine where the SDK works), the last panel in the installer asks if I want to start the SDK Manager, which is to say run the file SDK Manager.exe that is located in the SDK top level folder.  When I do, I get the error message Failed to execute  tools\android.bat:, error 2 The system cannot find the file specified.

              When I open a command window and cd to the SDK tools folder, I run android.bat from the command line and get the error message

              '"D:\dev\android\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command,
              operable program or batch file.

              The executable find_java.exe, which the message references, is actually called from within find_java.bat, both of which are in the tools\lib folder.

              Here's android.bat (in the SDK's tools folder), followed by find_java.bat...

              @echo off
              rem Copyright (C) 2007 The Android Open Source Project
              rem
              rem Licensed under the Apache License, Version 2.0 (the "License");
              rem you may not use this file except in compliance with the License.
              rem You may obtain a copy of the License at
              rem
              rem      http://www.apache.org/licenses/LICENSE-2.0
              rem
              rem Unless required by applicable law or agreed to in writing, software
              rem distributed under the License is distributed on an "AS IS" BASIS,
              rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
              rem See the License for the specific language governing permissions and
              rem limitations under the License.

              rem Useful links:
              rem Command-line reference:
              rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

              rem don't modify the caller's environment
              setlocal

              rem Set up prog to be the path of this script, including following symlinks,
              rem and set up progdir to be the fully-qualified pathname of its directory.
              set prog=%~f0

              rem Grab current directory before we change it
              set work_dir=%cd%

              rem Change current directory and drive to where the script is, to avoid
              rem issues with directories containing whitespaces.
              cd /d %~dp0


              rem Check we have a valid Java.exe in the path.
              set java_exe=
              call lib\find_java.bat
              if not defined java_exe goto :EOF

              set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar

              rem Set SWT.Jar path based on current architecture (x86 or x86_64)
              for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a

              :MkTempCopy
                  rem Copy android.bat and its required libs to a temp dir.
                  rem This avoids locking the tool dir in case the user is trying to update it.

                  set tmp_dir=%TEMP%\temp-android-tool
                  xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul
                  copy /B /D /Y lib\common.jar         %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\commons-codec*     %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\commons-compress*  %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\commons-logging*   %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\dvlib.jar          %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\guava*             %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\httpclient*        %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\httpcore*          %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\httpmime*          %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\layoutlib-api.jar  %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\org-eclipse-*      %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\sdk*               %tmp_dir%\lib\        > nul
                  copy /B /D /Y lib\swtmenubar.jar     %tmp_dir%\lib\        > nul

                  rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
                  set tools_dir=%cd%
                  cd /d %tmp_dir%

              :EndTempCopy

              rem The global ANDROID_SWT always override the SWT.Jar path
              if defined ANDROID_SWT set swt_path=%ANDROID_SWT%

              if exist "%swt_path%" goto SetPath
                  echo ERROR: SWT folder '%swt_path%' does not exist.
                  echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
                  goto :EOF

              :SetPath
              rem Finally exec the java program and end here.
              REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
              call "%java_exe% %REMOTE_DEBUG%" "-Dcom.android.sdkmanager.toolsdir=%tools_dir%" "-Dcom.android.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*

              rem EOF


              Here's find_java.bat...

              @echo off
              rem Copyright (C) 2007 The Android Open Source Project
              rem
              rem Licensed under the Apache License, Version 2.0 (the "License");
              rem you may not use this file except in compliance with the License.
              rem You may obtain a copy of the License at
              rem
              rem      http://www.apache.org/licenses/LICENSE-2.0
              rem
              rem Unless required by applicable law or agreed to in writing, software
              rem distributed under the License is distributed on an "AS IS" BASIS,
              rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
              rem See the License for the specific language governing permissions and
              rem limitations under the License.

              rem This script is called by the other batch files to find a suitable Java.exe
              rem to use. The script changes the "java_exe" env variable. The variable
              rem is left unset if Java.exe was not found.

              rem Useful links:
              rem Command-line reference:
              rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

              rem Check we have a valid Java.exe in the path. The return code will
              rem be 0 if the command worked or 1 if the exec failed (program not found).
              for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
              if not defined java_exe goto :CheckFailed

              :SearchJavaW
              rem Check if we can find a javaw.exe at the same location than java.exe.
              rem If that doesn't work, just fall back on the java.exe we just found.
              for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s -w') do set javaw_exe=%%a
              if not exist "%javaw_exe%" set javaw_exe=%java_exe%
              goto :EOF


              :CheckFailed
              echo.
              echo ERROR: No suitable Java found. In order to properly use the Android Developer
              echo Tools, you need a suitable version of Java JDK installed on your system.
              echo We recommend that you install the JDK version of JavaSE, available here:
              echo   http://www.oracle.com/technetwork/java/javase/downloads
              echo.
              echo If you already have Java installed, you can define the JAVA_HOME environment
              echo variable in Control Panel / System / Avanced System Settings to point to the
              echo JDK folder.
              echo.
              echo You can find the complete Android SDK requirements here:
              echo   http://developer.android.com/sdk/requirements.html
              echo.
              goto :EOF

              Lemonilla



                Apprentice

              • "Too sweet"
              • Thanked: 70
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              Re: luanch of executable from within .bat file fails
              « Reply #13 on: November 26, 2014, 09:47:33 PM »
              Try changing this line:
              for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
              to this:
              for /f "delims=" %%a in ('"%~dps0find_java.exe" -s') do set java_exe=%%a


              Also check that path to make sure that find_java.exe actually exists.
              Quote from: patio
              God Bless the DOS Helpers...
              Quote
              If it compiles, send the files.

              Jerry Ford

                Topic Starter


                Rookie

                • Experience: Expert
                • OS: Windows 7
                Re: luanch of executable from within .bat file fails
                « Reply #14 on: November 27, 2014, 12:03:51 AM »
                Lemonilla:

                The change you suggest replaces the double backslash with a single backslash in the path to find_java.exe, so  D:\dev\android\sdk\tools\lib\\find_java.exe becomes D:\dev\android\sdk\tools\lib\find_java.exe but either one works as a valid Windows path.  And yes, find_java.exe does exist at that location, and when I run it from the command line it returns a valid path...

                D:\dev\android\sdk\tools>lib\find_java.exe
                C:\ProgramData\Oracle\Java\javapath\java.exe
                D:\dev\android\sdk\tools>

                ...which does point to the java executable in my JDK...

                D:\dev\android\sdk\tools>C:\ProgramData\Oracle\Java\javapath\java.exe -version
                java version "1.8.0_25"
                Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
                Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

                But attempts to run the Android SDK Manager or andriod.bat still fail.