Passing commands in CMD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lumpybanana247
    New Member
    • Apr 2007
    • 134

    Passing commands in CMD

    So, I wanted to compile my java script in CMD via my C++ application.
    I tried
    system("cd C:\\ && javac HelloWorldApp.j ava");
    and
    system("cd C:\\ & javac HelloWorldApp.j ava");
    which neither of them work

    although, when i use cmd.exe and manually type
    cd C:\\ && javac HelloWorldApp.j ava
    everything works fine.
    anybody have any suggestions?


    EDIT
    even when the file is in my directory C:\docs and settings\my username\
    and i use this
    system("javac HelloWorldApp.j ava");
    ..when opening cmd and typing javac HelloWorldApp.j ava works...
    doesnt work
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    This may just be the wine talking, but have you considered 'escaping' them like you did the slash in the path?

    ie

    system("cd C:\\ \&\& javac HelloWorldApp.j ava");


    ?

    Comment

    • lumpybanana247
      New Member
      • Apr 2007
      • 134

      #3
      Originally posted by sicarie
      This may just be the wine talking, but have you considered 'escaping' them like you did the slash in the path?

      ie

      system("cd C:\\ \&\& javac HelloWorldApp.j ava");


      ?
      thanks for your response. i have tried that and it had the same error... i edited my question right before you posted saying
      opening CMD.exe and typing "cd C:\ && javac HelloWorldApp.j ava" works, but using system and doing "system("cd C:\ && javac HelloWorldApp.j ava" does not work

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by lumpybanana247
        thanks for your response. i have tried that and it had the same error... i edited my question right before you posted saying
        opening CMD.exe and typing "cd C:\ && javac HelloWorldApp.j ava" works, but using system and doing "system("cd C:\ && javac HelloWorldApp.j ava" does not work

        I have another idea.
        Put all the command in a .bat file and call the bat file from your code.
        Check whether this works

        Raghuram

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          And you tried escaping the '&'s specifically, as I posted above?

          (As well as using the full path to the Java executable?)
          Last edited by sicarie; Jan 14 '08, 01:29 AM. Reason: As well as..

          Comment

          • lumpybanana247
            New Member
            • Apr 2007
            • 134

            #6
            Originally posted by sicarie
            And you tried escaping the '&'s specifically, as I posted above?

            (As well as using the full path to the Java executable?)

            thank you guys for your help.
            it turns out for some reason, the current directory (cd) is ?Not set?... so i jsut typed

            system("javac C:\\Docume~1\\U SERNAME\\FILE.j ava");


            thank you

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              I'm guessing it is that the directory of the java executable is not in the path. If you added that folder to the path, you should be able to call it locally.

              Comment

              Working...