Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I am new to linux c programming, i need to write a C program logic on how to execute a command through a serial port from one pc to another pc

For example:-

I am having a two PC connected via usb to serial cable. I need to execute the command for eg;-
ls
to list the file in another computer via usb to serial.

But when i tried to write a command it received as a plain string not a command, can any one tell me how do i execute the terminal command from one pc to another pc via /dev/ttyUSB with the help of c program



Thanks
shan
Posted

1 solution

You will have to execute the command via the C code on the target machine, retrieve the information, and send it back to the original computer via the serial port.
The system[^] function will probably help.
 
Share this answer
 
Comments
[no name] 24-Jan-14 15:58pm    
To add to Griff's response (which precisely answers the question) - passing incoming text to the system() function creates a gaping security hole. It would be better to assign the tty device to a getty process. Attempts to interact over the tty port would be first greeted with a prompt for username/password. After logging in, the remote machine could issue normal shell commands like cat and ls.

http://www.tldp.org/HOWTO/html_single/Text-Terminal-HOWTO/#ss15.1

Of course, this becomes an exercise in administration, not programming.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900