Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel.exec cannot launch two .bat files separated by && #809

Closed
mdeb opened this issue Jun 18, 2013 · 9 comments
Closed

Kernel.exec cannot launch two .bat files separated by && #809

mdeb opened this issue Jun 18, 2013 · 9 comments

Comments

@mdeb
Copy link

mdeb commented Jun 18, 2013

Given that Java 1.7.0_21 is installed, when running the system command, a command having the && operator to run another command, it gives the following error, "&& was unexpected at this time".

So for example:

C:\test.bat && C:\test.bat

"&& was unexpected at this time".

I reinstalled Java 1.7.0_11 and the problem was solved.

@BanzaiMan
Copy link
Member

I don't think there is anything we can do here. The error message is coming from Windows. If it is JVM, as you suspect, then I suggest filing a bug report with Oracle/OpenJDK.

@mdeb
Copy link
Author

mdeb commented Jun 19, 2013

I tried this sample code on Java 1.7.0_11 and Java 1.7.0_21.

From the JRuby, both of the batch files were executed on 1.7.0_11,

The problem is that on 1.7.0_21 only the first batch file was executed.

The sample code run from the Rakefile is:

desc 'Run batch...'
task :runbatch do |task_name, args|
command = "C:\Users\matthewd\Desktop\tbat.bat && cmd /c start C:\Users\matthewd\Desktop\tbattwo.bat"
system command
end

From a Java standpoint, both of the batch files were executed on 1.7.0_11 and 1.7.0_21

The sample code run from Java is:

import java.util.;
import java.io.
;

public class test {

public static void main(String[] args)
{
    try {

        String path = ("cmd /c start C:\\Users\\matthewd\\Desktop\\tbat.bat && cmd /c start C:\\Users\\matthewd\\Desktop\\tbattwo.bat");
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec(path); 
         } 
        catch(IOException ioException) 
        {
                System.out.println(ioException.getMessage());
        }
}

}

@headius
Copy link
Member

headius commented Jun 23, 2013

Ok, so the problem here is in how we handle running a command line that contains a && when on Windows.

I believe we currently run such code by passing it to cmd /c. Perhaps you can do some investigation from there to see if there's a different way we should run this so it will execute as you expect?

I do not personally have a Windows machine I can investigate this on.

I'd also be interested in whether this works from C Ruby.

@headius headius reopened this Jun 23, 2013
@mdeb
Copy link
Author

mdeb commented Jun 27, 2013

The command can be simplified to

"tbat.bat && tbattwo.bat" in the Ruby script and as already mentioned, in Java 1.7.0_11 it executes both batch files, whilst in Java 1.7.0_21 it only executes the first.

As for C Ruby, I ran it on ruby 2.0.0p195 (2013-05-14) [i386-mingw32], and it executed both batch files.

My guess is that Java made some changes in Runtime.exec (http://www.oracle.com/technetwork/java/javase/7u21-relnotes-1932873.html), could this be the source of the problem?

@headius
Copy link
Member

headius commented Jun 27, 2013

On Thu, Jun 27, 2013 at 2:53 AM, mdeb notifications@github.com wrote:

The command can be simplified to

"tbat.bat && tbattwo.bat" in the Ruby script and as already mentioned, in Java 1.7.0_11 it executes both batch files, whislt in Java 1.7.0_21 it only executes the first.

As for C Ruby, I ran it on ruby 2.0.0p195 (2013-05-14) [i386-mingw32], and it executed both batch files.

My guess is that Java made some changes in Runtime.exec (http://www.oracle.com/technetwork/java/javase/7u21-relnotes-1932873.html), could this be the source of the problem?

That is a strong possibility. Nothing in our process launching logic
would be different between those two Java versions. In any case, we
will have to investigate, since we can't just blame the JDK and not
try to work around it ourselves.

Would it be possible for you to provide Java code that attempts to
launch two scripts in this way, so we can use that as a basis for
investigating a workaround?

  • Charlie

@mdeb
Copy link
Author

mdeb commented Jun 28, 2013

The java code I used to launch the two batch files, the command line executed is simplified to "tbat.bat && tbattwo.bat", and this will execute both the batch files.

import java.util.;
import java.io.
;

public class test {

public static void main(String[] args)
{
    try
    {
        String path = ("tbat.bat && tbattwo.bat");
        Runtime runtime = Runtime.getRuntime();
        Process p = runtime.exec(path); 
        String s;
        BufferedReader stdout = new BufferedReader (new InputStreamReader(p.getInputStream()));
        while ((s = stdout.readLine()) != null) 
        { 
            System.out.println(s); 
        }
    } 
    catch(Exception e) 
    {
        e.printStackTrace();
    }   
}

}

@headius headius modified the milestones: JRuby 1.7.12, JRuby 1.7.10 Feb 21, 2014
@enebo enebo modified the milestones: JRuby 1.7.13, JRuby 1.7.12 Apr 15, 2014
@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.13 Jun 24, 2014
@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.15 Aug 27, 2014
@kares kares modified the milestones: JRuby 1.7.27, JRuby 1.7.15 Jan 20, 2017
@enebo enebo changed the title JRuby and Java 1.7.0_21 Interpreter bug Kernel.exec cannot launch two .bat files separated by && Feb 17, 2017
@enebo enebo removed this from the JRuby 1.7.27 milestone Apr 24, 2017
@olleolleolle
Copy link
Member

olleolleolle commented Feb 26, 2018

Does this gist represent the issue?
https://gist.github.com/olleolleolle/751fb332954c59dc895735f7f6d420b9

I ran that like this: java -jar jruby-complete-1.7.27.jar -Srake runbatch - and it ran both commands.

(tbattwo.bat is run inside a new shell. That's what cmd \c start does, I take it.)

(Windows 10 Enterprise 2016 LTSB. Version 1607. Os Build: 14393.2007. 64-bit.)

C:\Users\olle\Downloads\download>java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) Client VM (build 25.151-b12, mixed mode, sharing)

@headius
Copy link
Member

headius commented Mar 19, 2018

@olleolleolle So maybe this is no longer an issue? It has been sitting on the shelf for a long time.

@olleolleolle
Copy link
Member

@headius For me, with the situation above, it worked.

I think it's fair to close this issue.

@headius headius closed this as completed Mar 19, 2018
@headius headius added this to the JRuby 1.7.27 milestone Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants