views:

209

answers:

3

I have a bat file with the following contents:

set logfile=  D:\log.txt

java com.stuff.MyClass %1 %2 %3  >> %logfile%

when I run the bat file though, I get the following:

C:\>set logfile= D:\log.txt

C:\>java com.stuff.MyClass <val of %1> <val of %2> <val of %3>   1>>D:\log.txt
The parameter is incorrect.

I'm almost positive the "The parameter is incorrect." is due to the extraneous 1 in there. I also think this might have something with the encoding of the .bat file, but I can't quite figure out what is causing it. Anyone ever run into this before or know what might be causing it and how to fix it?

Edit

And the lesson, as always, is check if its plugged in first before you go asking for help. The bat file, in version control, uses D:\log.txt because it is intended to be run from the server which contains a D drive. When testing my changes and running locally, on my computer which doesn't have a D drive, I failed to make the change to use C:\log.txt which is what caused the error. Sorry for wasting you time, thanks for the help, try to resist the urge to downvote me too much.

+3  A: 

I doubt that that's the problem - I expect the command processor to deal with that part for you.

Here's evidence of it working for me:

Test.java:

public class Test
{
    public static void main(String args[]) throws Exception
    {
        System.out.println(args.length);
        for (String arg : args)
        {
            System.out.println(arg);
        }
    }
}

test.bat:

set logfile= c:\users\jon\test\test.log
java Test %1 %2 %3 >> %logfile%

On the command line:

c:\Users\Jon\Test> [User input] test.bat first second third

c:\Users\Jon\Test>set logfile= c:\users\jon\test\test.log

c:\Users\Jon\Test>java Test first second third  1>>c:\users\jon\test\test.log

c:\Users\Jon\Test> [User input] type test.log
3
first
second
third
Jon Skeet
+2  A: 

the 1 is not extraneous: it is inserted by cmd.exe meaning stdout (instead of ">>", you can also write "1>>". contrast this to redirecting stderr: "2>>"). so the problem must be with your parameters.

ax
+1  A: 

This may seem like a stupid question, but is there an existing D: drive in the context that the bat file runs in?

Once I had a case where a bat file was used as the command line of a task within the Task Manager, but the Run As user was set to a local user on the box, giving no access to network drives.

Interpolated for your case, if the D: drive were a network drive, running the bat file as, say, the local administrator account on that machine instead of a domain user account would likely fail to have access to D:.

David M. Miller
thanks, that was it. I did notice the error and fixed it before your response, but you managed to nail it.
shsteimer