Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    Tạo tool compile và run code C/C++ trên web bằng Nodejs

    Hỏi Đáp
    0
    5
    1379
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      nguyễn việt dũng234 last edited by

      Tình hình là em muốn tạo 1 web để compile và run code C/C++ rồi in ra kết quả bằng nodejs (nó cũng như khi mình chạy chương trình trên depcpp hay codeblock) nhưng chưa biết làm sao và cũng chưa có hướng đi cụ thể nào. Mọi người ai biết hay đã từng làm có thể cho mình xin chút chỉ dẫn được hem ạ????

      Vũ 1 Reply Last reply Reply Quote 0
      • Vũ
        Vũ Global Moderator @nguyễn việt dũng234 last edited by

        @nguyễn-việt-dũng234 Mình chưa làm nhưng từ khóa cpp sandbox có thể giúp bạn 🙂

        Khi dựng được sandbox rồi thì bạn có thể tương tác với nó qua API. Dĩ nhiên là có thể run đc trên web + nodejs.

        Tech-nông
        Email: [email protected]
        Profile: about.me/vunb
        Github: github.com/vunb
        Twitter: twitter.com/nhubaovu

        N 1 Reply Last reply Reply Quote 0
        • C
          Công Lương Ngô last edited by Công Lương Ngô

          Không biết bạn sử dụng server Windows hay Linux? Nếu là server linux bạn có thể thử các bước sau:

          1. Dùng fs.writeFile để tạo file cpp từ nội dụng trên website, sau đó ghi lên server.
          2. Dùng child process (reference) thực thi lệnh g++ để compile ra file runable.
          3. Dùng child process như trên để thực thi file runable vừa compile ra.

          Tuy nhiên bạn cần phải cẩn thận vì đây là 1 lỗ hổng lớn đối với hệ thống đấy nhé
          Ví dụ:

          const { execFile } = require('child_process');
          const child = execFile('g++', ['hello.cpp','-o','hello'], (error, stdout, stderr) => {
              if (error) {
          	    throw error;
              }
              console.log(stdout);
              const child = execFile('./hello', (error, stdout, stderr) => {
                  if (error) {
                      throw error;
                  }
                  console.log(stdout);
              });
          });
          
          N 1 Reply Last reply Reply Quote 0
          • N
            nguyễn việt dũng234 @Vũ last edited by

            @Vũ said in Tạo tool compile và run code C/C++ trên web bằng Nodejs:

            @nguyễn-việt-dũng234 Mình chưa làm nhưng từ khóa cpp sandbox có thể giúp bạn 🙂

            Khi dựng được sandbox rồi thì bạn có thể tương tác với nó qua API. Dĩ nhiên là có thể run đc trên web + nodejs.

            oh cảm ơn bạn để mình thử

            1 Reply Last reply Reply Quote 0
            • N
              nguyễn việt dũng234 @Công Lương Ngô last edited by

              @Công-Lương-Ngô said in Tạo tool compile và run code C/C++ trên web bằng Nodejs:

              Không biết bạn sử dụng server Windows hay Linux? Nếu là server linux bạn có thể thử các bước sau:

              1. Dùng fs.writeFile để tạo file cpp từ nội dụng trên website, sau đó ghi lên server.
              2. Dùng child process (reference) thực thi lệnh g++ để compile ra file runable.
              3. Dùng child process như trên để thực thi file runable vừa compile ra.

              Tuy nhiên bạn cần phải cẩn thận vì đây là 1 lỗ hổng lớn đối với hệ thống đấy nhé
              Ví dụ:

              const { execFile } = require('child_process');
              const child = execFile('g++', ['hello.cpp','-o','hello'], (error, stdout, stderr) => {
                    if (error) {
              	    throw error;
                    }
                console.log(stdout);
                const child = execFile('./hello', (error, stdout, stderr) => {
                    if (error) {
                        throw error;
                    }
                    console.log(stdout);
                });
              });
              

              tiếc quá. mình dùng windows à 😃

              1 Reply Last reply Reply Quote 0
              • First post
                Last post