Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

การใช้งาน system() ใน C/C++: รันคำสั่งระบบ

ฟังก์ชัน system() ใช้รันคำสั่ง command line จากภายในโปรแกรม C/C++

ตัวอย่าง 1: ดู IP Config (Windows)

#include <cstdlib>
int main() {
    system("ipconfig");
    return 0;
}

ตัวอย่าง 2: Shutdown คอมพิวเตอร์ (Windows)

#include <cstdlib>
int main() {
    system("shutdown /s");
    return 0;
}

คำเตือน: system() มีความเสี่ยงด้านความปลอดภัย (command injection) ควรหลีกเลี่ยงใน production code