Mở nhiều cmd để chạy code?

Mọi người cho mình hỏi cách viết script để mở nhiều cmd (chạy nhiều code cùng lúc). Save dưới dạng .cmd càng tốt :smiley:
Ví dụ: Mình có file test.cmd gồm nhiều dòng, mỗi dòng 1 lệnh gần tương tự nhau (chỉ khác vài số cuối). Nhưng mỗi dòng chạy liên tiếp nhau, mình cần mở nhiều cmd để chạy cùng lúc thì có cách nào không :smiley: copy-paste thì hơi củ chuối quá.

3 Likes

Em muốn mở nhiều cmd lên rồi tự gõ lệnh vào bằng tay hay muốn chạy hết tất cả cùng lúc?

3 Likes

Đang nghỉ hướng như thế này:
Mỗi một chương trình tạo .bat để call chương trình chạy,
sau sẽ tạo main.bat để gọi những bat file đã tạo, như vậy vừa độc lập từng app vừa đáp ứng yêu cầu.
Không biết hiểu đúng câu hỏi không ta :smiley:

3 Likes

Anh thử lệnh kiểu này xem:

os.system("start python newProcessTest.py %s %s" % arg1, arg2)

Mà sao anh không dùng thread á :smile:


À mà cái trên chỉ chạy trên windows thôi thì phải, trên ubuntu phải chơi kiểu này :smile:

os.system('gnome-terminal -x sh -c "python newProcessTest.py %s %s;exec bash;"' % (arg1, arg2))

Mà em thấy người ta bảo dùng subprocess ngon hơn, anh thử ngâm cứu xem :smile_cat:

3 Likes

Em có một file thế này

.\puzzle_heuristic.exe 2 .\puzzle31.txt .\result312.txt
.\puzzle_heuristic.exe 2 .\puzzle32.txt .\result322.txt
.\puzzle_heuristic.exe 2 .\puzzle33.txt .\result332.txt
.\puzzle_heuristic.exe 2 .\puzzle34.txt .\result342.txt
.\puzzle_heuristic.exe 2 .\puzzle35.txt .\result352.txt
.\puzzle_heuristic.exe 2 .\puzzle41.txt .\result412.txt
.\puzzle_heuristic.exe 2 .\puzzle42.txt .\result422.txt
.\puzzle_heuristic.exe 2 .\puzzle43.txt .\result432.txt
.\puzzle_heuristic.exe 2 .\puzzle44.txt .\result442.txt
.\puzzle_heuristic.exe 2 .\puzzle45.txt .\result452.txt
.\puzzle_heuristic.exe 2 .\puzzle51.txt .\result512.txt
.\puzzle_heuristic.exe 2 .\puzzle52.txt .\result522.txt
.\puzzle_heuristic.exe 2 .\puzzle53.txt .\result532.txt
.\puzzle_heuristic.exe 2 .\puzzle54.txt .\result542.txt
.\puzzle_heuristic.exe 2 .\puzzle55.txt .\result552.txt
.\puzzle_heuristic.exe 1 .\puzzle31.txt .\result311.txt
.\puzzle_heuristic.exe 1 .\puzzle32.txt .\result321.txt
.\puzzle_heuristic.exe 1 .\puzzle33.txt .\result331.txt
.\puzzle_heuristic.exe 1 .\puzzle34.txt .\result341.txt
.\puzzle_heuristic.exe 1 .\puzzle35.txt .\result351.txt
.\puzzle_heuristic.exe 1 .\puzzle41.txt .\result411.txt
.\puzzle_heuristic.exe 1 .\puzzle42.txt .\result421.txt
.\puzzle_heuristic.exe 1 .\puzzle43.txt .\result431.txt
.\puzzle_heuristic.exe 1 .\puzzle44.txt .\result441.txt
.\puzzle_heuristic.exe 1 .\puzzle45.txt .\result451.txt
.\puzzle_heuristic.exe 1 .\puzzle51.txt .\result511.txt
.\puzzle_heuristic.exe 1 .\puzzle52.txt .\result521.txt
.\puzzle_heuristic.exe 1 .\puzzle53.txt .\result531.txt
.\puzzle_heuristic.exe 1 .\puzzle54.txt .\result541.txt
.\puzzle_heuristic.exe 1 .\puzzle55.txt .\result551.txt

đại loại như vậy có cách nào call cùng lúc nhau ko?
mà gọi lệnh system() là được phải ko nhỉ?

1 Like

Thế là phải làm bằng file bat hả a? A thử gõ trên cmd start .\puzzle_heuristic.exe 1 .\puzzle55.txt .\result551.txt xem nó có nhảy là một cái cmd mới không? Em nhớ là trên windows đặt start ở đầu lệnh nó sẽ tạo ra một cái cmd khác chạy cái lệnh sau đó, còn xử lí vòng lặp với file bat thì em chịu :sweat_smile:

3 Likes

À được rồi, để tìm hiểu xem có loop ko :smiley:

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?