13 Replies Latest reply on Sep 12, 2009 4:20 PM by -==cfSearching==-

    Problem Executing Batch File

    Amosl

      I wrote out a java class that I tried using cfobject to call. It didn't work. So I wrote a batch file to call the java class.  The batch file works, but NOt when I have coldfusion call it. Nothing happens, no error... nothing.  I thought it might be a permissions issue, but I tried changing permissions for coldfusion although I may have doneit wrong since I'm not too familiar with Vista.  Can anyone offer advice on what I can do.  Its a simple java class and I can't get it to run.  no errors in the log.  There isn't much for me to go on.  All I know is that the class and batch file work fine if Coldfusion doesn't call them.

        • 1. Re: Problem Executing Batch File
          Amosl Level 1

          also I added the class path in the administrator so that is not the issue with cfobject at least.  I know this is not relevant when trying to call the batch file

          • 2. Re: Problem Executing Batch File
            -==cfSearching==- Level 4

            Amosl wrote:

             

            I wrote out a java class that I tried using cfobject to call. It didn't work.

            What do you mean "didn't work"?  Was there an error message, the object did not behave as expected,  ....?  Without knowing more some of the more common problems are:

             

            1) Failing to put java objects in the _CF_ class path

            2) Forgetting to reboot the CF server. Some changes are only detected when the CF server starts up

            3) Calling the class with an incorrect path. For example, omitting the package path or using the wrong cAsE

             

            Amosl wrote:

             

            I thought it might be a permissions issue, but I tried changing permissions for coldfusion although I may have doneit wrong since I'm not too familiar with Vista.  Can anyone offer advice on what I can do.  Its a simple java class and I can't get it to run.

             

            I cannot assist you with Vista.  But what does this class do? It is difficult to offer advice without more specifics or seeing the java code.

            • 3. Re: Problem Executing Batch File
              Amosl Level 1

              sorry for not being clear but I have little to go on.  By its not working, I mean to say, nothing happened. The browser gives the indication that it ran by showing no error messages.  I checked the logs as well and no error messages.

              The class path is set up correctly.  I know this because I tested for this by moving it somewhere else and I get the classpath error.  I then put it back and no error.

               

              I've rebooted the server about 50 times and the computer several times.

               

              To limit the problems with the class itself and cfobject, I've created a batch file to run the class.  The batch file runs the class fine, so long as I execute the batch via command line.  But coldfusion doesn't execute the batch with cfexecute.  the same exact problem with absolutely no error messages.

               

              However, if I give cfexecute a timeout, I get the message that cfexecute timed out.

               

              From the 100's of pages I've read online with people with similar problems, this seems to be a permissions issue.  however, I've set Coldfusion to run as me, the administrator and only person who uses this computer.  It is no longer running as local system.

               

              However, this didn't fix anything.  My only guess is that perhaps I've no set it to run as me correctly.  But I have no way of testing this.  Windows logs show no error messages either.  Is there any way to have coldfusion show me what user its trying to execute the batch as.

               

              All that the batch does is write a file to the server.  I am testing with the most basic of batches.

               

              However,  if I create a java class in the same folder that doesn't write to the system and only returns variables, it works fine.  This indicates the class path is set correctly and that cfobject does work.

               

              As far as the java code goes for the class I am testing, the code works, since command line works.

               

              I've spent like 8 hours on this and nothing seems to work. Any help would be greatly appreciated.

               

              I am almost 100% sure this is a permissions issue and wonder if there's a way to force windows to log who tried to access the batch file and record any errors.

              • 4. Re: Problem Executing Batch File
                -==cfSearching==- Level 4

                Amosl wrote:

                 

                To limit the problems with the class itself and cfobject, I've created a batch file to run the class.  The batch file runs the class fine, so long as I execute the batch via command line.  But coldfusion doesn't execute the batch with cfexecute.  the same exact problem with absolutely no error messages.

                 


                Unfortunately, cfexecute is not the easiest tag to debug. In my experience sometimes it confuses more than clarifies.  But trying it is not a bad idea from a troubleshooting point of view.

                 

                However,  if I create a java class in the same folder that doesn't write to the system and only returns variables, it works fine.  This indicates the class path is set correctly and that cfobject does work.

                 

                Yes, I would agree.

                 

                It does sound like it might be a permissions issue. But I have little experience with Vista, so there may well be another cause.  Since it sounds like you are just testing a very simple java class, can you post the code for the class itself as well as the exact cfexecute code you are using? I could test it on another operating system. Just to see if there is some obvious problem.

                 

                Amosl wrote:

                 

                From the 100's of pages I've read online with people with similar problems, this seems to be a permissions issue.  however, I've set Coldfusion to run as me, the administrator and only person who uses this computer.  It is no longer running as local system.

                 

                However, this didn't fix anything.  My only guess is that perhaps I've no set it to run as me correctly.  But I have no way of testing this.  Windows logs show no error messages either.  Is there any way to have coldfusion show me what user its trying to execute the batch as.


                I believe the user account can be obtained from the java system properties.  Try:

                 

                <cfset sys = createObject("java", "java.lang.System")>
                <cfoutput>
                   <b>user.name</b> = #sys.getProperty("user.name", "not found")#<hr>
                   <b>coldfusion.classPath</b> = #sys.getProperty("coldfusion.classPath")#<br>
                </cfoutput>

                • 5. Re: Problem Executing Batch File
                  Amosl Level 1

                  its showing the correct user name.  i just tried executing the batch by creating a jsp page and the same thing happened.  I'm pretty much convinced its a permissions issue.

                  • 6. Re: Problem Executing Batch File
                    -==cfSearching==- Level 4

                    Well, how you are calling the batch file might also have an effect.  But that is about all I can offer without seeing some code.

                    • 7. Re: Problem Executing Batch File
                      Amosl Level 1

                      Ok here's a very simplified version of the code.  Dy doing this I found something interesting.  The echo call is output onto the coldfusion page, but it is not written to the file.  When I do it command line the echo call is displayed on the command line interface and the file is written.

                       

                       

                      Here's the cfexecute code in a file called getpixels.cfm:

                       

                       

                      <cfexecute name="C:\Users\Amos\Desktop\javacode\run2.bat"
                      timeout="35"></cfexecute>

                       

                       

                      The batch file called run2.bat has the following code:

                       

                      Echo %Date%, %Time% >> filename.txt

                       

                      i removed the java class from the batch file sine that doesn't seem to be the problem.

                       

                      however,  the batch file would have the following code:

                       

                      java ScreenCapture

                      • 8. Re: Problem Executing Batch File
                        Amosl Level 1

                        ho ho!  I think I may have figured it out..  I'll get back.  This simplified version showed me that it may be outputing the file to the codlfusion runtime bin.  I searched for the file in other locations but vista may not have the bin indexed.

                         

                        Although I don't want to get too excited yet. i think there may still be a different problem

                        • 9. Re: Problem Executing Batch File
                          -==cfSearching==- Level 4

                          The echo call is output onto the coldfusion page, but it is not written to the file.

                           

                          I do not get that behavior with CF8 (what version are you using?)  Though I have seen that mentioned before.

                          http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Util ities

                           

                          I usually execute batch files using cmd.exe instead, rather than trying to call them directly:

                           

                          <cfexecute name="c:\windows\system32\cmd.exe"
                              arguments="/c C:\run2.bat"
                              timeout="35">
                          </cfexecute>

                          • 10. Re: Problem Executing Batch File
                            -==cfSearching==- Level 4

                            Amosl wrote:

                             

                            ho ho!  I think I may have figured it out..  I'll get back.  This simplified version showed me that it may be outputing the file to the codlfusion runtime bin.  I searched for the file in other locations but vista may not have the bin indexed.

                             

                             

                             

                            Not completely surprising since the .bat file does not supply a full path to the output file!  Always use absolute paths, or the location is determined by the execution context ;-)

                            • 11. Re: Problem Executing Batch File
                              Amosl Level 1

                              I tried executing the command the way you had suggested but that never worked. I still seem to have a problem, but I think that the problem now is with my java code.  I'll start another thread if this continues.  Thanks For Your help!!!!!

                               

                              We can consider this one closed although I should know soon if this other problem is related.

                              • 12. Re: Problem Executing Batch File
                                -==cfSearching==- Level 4

                                Amosl wrote:

                                 

                                I tried executing the command the way you had suggested but that never worked.


                                 

                                Maybe not.  Usually people leave off the leading "/c".  But I am glad you are making progress now.

                                • 13. Re: Problem Executing Batch File
                                  -==cfSearching==- Level 4

                                  however,  the batch file would have the following code:

                                   

                                  java ScreenCapture

                                   

                                  For the record, that may be one of your problems. You are calling both java.exe and the class without a path or context. That can be problematic if the exe is not being called from the correct location.

                                   

                                  Use caution calling "java.exe" without a full path. IIRC I had some problems with that once because I had multiple versions of java installed.  So my code was actually using a different JRE  _not_ the one being used by CF. So the classpath was not what I thought it was....