w3resource logo

:

C Programming Exercises

C Exercises: Invoke the command processor to execute a command

C Variable Type: Exercise-1 with Solution

Write a C program which will invoke the command processor to execute a command.

Sample Solution:

C Code:

#include<stdio.h>
#include<stdlib.h>

int main ()
	{
		int x;

		printf ("\n\nIs command processor available?\n");
		if (system(NULL))
		{
			printf ("Command processor available!\n");
		}
		else
		{
			printf ("Command processor not available!\n");
			exit (1);
		}
		printf ("Executing command DIR\n");
		x=system ("dir");
		printf ("Returned value is: %d.\n",x);
		return 0;
	} 
  

Sample Output:

Is command processor available?                                                                               
Command processor available!                                                                                  
Executing command DIR                                                                                         
0101d560-54e9-11e7-a85b-5dffbb229414    7d2db170-55a9-11e7-be91-9d836d04a23e                                  
0137a4a0-55a8-11e7-89d9-6907ca0db017    7d3f5910-5195-11e7-8c7b-836f726e36d0                                  
015b94c0-4a8e-11e7-8e36-ebbcdd3971ae    7d630300-57fe-11e7-9381-9d994cae8e36                                  
015c43a0-55a8-11e7-89d9-6907ca0db017    7de4f070-51ac-11e7-ae6a-cd387a54803c                                  
01991c80-4a9a-11e7-a463-0d368a9e12b1    7e280e40-57de-11e7-ba21-b9739f8cb956                                  
01ae5930-51a0-11e7-80b0-cbb971bc6112    7e814da0-445d-11e7-b771-21ad0f863a1c                                  
01d3bd20-49ed-11e7-8ea6-611e29526b70    7eb35360-4b5e-11e7-a793-e3da3ad86a97                                  
01d7b150-4a88-11e7-804e-0b936a3310fd    7f2db220-54e3-11e7-b89b-7d525be75d15                                
-----
7d056f80-50f4-11e7-8ba9-adac345928ff  temp.txt                                                                
7d2db170-55a9-11e7-be91-9d836d04a23e  test.png                                                                
7d3f5910-5195-11e7-8c7b-836f726e36d0  test.txt                                                                
7d630300-57fe-11e7-9381-9d994cae8e36                                                                          
Returned value is: 0.

C Programming Code Editor:

Improve this sample solution and post your code through Disqus