Link to home
Start Free TrialLog in
Avatar of BeginToLearn
BeginToLearn

asked on

command line may cause bugs

hi all,
 After I updated my program to  transfer everyting from src directory to dest directory by creating all hierarchy folder first ( new features) then transfer all files. I use the "system"  command to creat new folder. However, I don't know how to make sure the "system" command finish before flow of program continue .I suspect it cause bug.

Current working dir: /home/ubuntu/program
 directory is : /home/ubuntu/program/src/dir1
 directory is : /home/ubuntu/program/src/dir1/dir2a
 directory is : /home/ubuntu/program/src/dir1/dir2a/dir4
 directory is : /home/ubuntu/program/src/dir1/dir2
 directory is : /home/ubuntu/program/src/dir1/dir2/dir3

ubuntu@ubuntu:~/program$ ./server
message2-> dirname is : /home/ubuntu/program/src/dir1
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a/dir4
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a/dir4
/home/ubuntu/program/dest/dir1/dir2a/dir4 is existed
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2/dir34
 received wrong size_to_read: No such file or directory
ubuntu@ubuntu:~/program$

Tks for your advise.
PS: one idea just pop up. in this case, the quick way is to check the directory existance after "system" command????

   
client.c
server.c
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you check the man pages of system you will see that the child process which was started by system must terminate before system returns to the calling (server) process.

Sara
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BeginToLearn
BeginToLearn

ASKER

oh tks Sara. I am also rework on my get_all_files(). Testing now :)
i think it works perfect now.
client.c
server.c
good job :)

one last remark,

if you would clear the static buffer after each message the buffer automatically would be zero-terminated in case of text messages.

Sara
oh you mean after I receive the message, i should clear the static buffer?  Is it same effective like i use memset() to set static buffer before receving message?
no, my fault, you can't clear it after the message cause the buffer was returned to the caller. but you can do memset before the while loop.

because maximum message length is 2048 and the buffer is 2049 you always have at least 1 zero char left if you do proper initialisation before recv. for message 3 that is irrelevant cause it may contain binary data as well. but for string message like message 2 it makes the handling (and debug output) simpler.

Sara
I get the idea. tks. Let me close this question. I will rework to make it sending to multiple server.