CMD opening

FluFlu
edited June 2014 in Questions about Code

Can somebody help me with this? I need to do this project fast, but it won't work like the example in the open() reference on the Processing site. So it says there that to write a command in the windows cmd, I first need to open it with open(cmd/c); and after that to put a string array consisting of one command or more to be executed in the cmd, but it simply doesn't work, and I don't get it why... can someone give me a test program consisting the command "ping www.google.com > test.txt" please? It just wouldn't work at me. The program executes, I press in the program window with my mouse ( the open() and the other instructions are found in void mousePressed() ) and when I check the test.txt, it doesn't appear anything but blank. Please, I really need this get working!

Tagged:

Answers

  • Yes. Show some code, dude.

  • void setup() {
      size(200, 200);
    }
    
    void draw() { 
     background(225);
    }
    
    void mousePressed() {
      String[] params = { 
        "cmd.exe", "ping wwww.google.com > test.txt"
      };
      open(params);
    }
    
  • Is that windows?

    It won't work in browser

    What about /c

    ?

    ;-)

  • Yes, I am in windows, and I tried like a hundred options to write it in different ways, including this. I think I need to add that I put my program in the system32 folder in windows.

  • void setup() { size(200, 200); }

    void draw() { background(0); }

    void mousePressed() { String[] params = { "cmd.exe", "ping wwww.gogole.com > test.txt" }; open(params); }

  • Ok, the alignment is messed up but I think you can understand it, it's short and simple...

  • open() reference:

    On Windows, the parameters are sent to the Windows shell via "cmd /c".

    So the cmd.exe part is redundant. And you put too much info in one string, you must split it, as stated.

      String[] params = {
        "ping", "wwww.google.com"
      };
      open(params);
    

    I don't recall exactly, but I don't think that redirection, pipes and the like work there.

  • Answer ✓

    Of course, you can make a little .cmd (or .bat) file that holds your command with redirection, and run it instead.

  • FluFlu
    edited June 2014

    I Think I will go with the .bat file idea, sounds good. Thank you!

Sign In or Register to comment.