LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-20-2012, 09:54 PM   #1
akshay_satish
Member
 
Registered: May 2011
Posts: 63

Rep: Reputation: Disabled
file transfer using pipes


Hi i had mistakenly opened another question under the same thread.
Code:
//argv will contain the scp cmd
       ret = posix_spawnp(
            &pid,
            argv[0], 
            NULL, NULL,
            argv,
            NULL);                      //After this i perform a waitpid();

ret = waitpid(pid,&status,0);
if(ret != pid) {
/*failed*/
}
else{
error = WEXITSTATUS(status);
                if (WIFEXITED(status) && error == 0) {
                    "blah blah"
                } else {
                    "blah blah" //failed the downld.
   
                    switch (...) {
                    case a:
                    case b:
                        printf("WHOOPS: scp exited with status %d\n", error);
                        break;
                    default:
                        break;
}
}
I want to catch the return value of scp command which i present in argv and print out a message using strerror. Dwhitney67 i can't access the information you had helped me with on the below link-->
http://www.linuxquestions.org/questi...se-4175435271/

I would really appreciate if you could shed some thoughts. In the program you had written, frets seems to be giving NULL within the output buffer even though the popen was successful. Basically even for a malformed command it was giving me a message saying Transfer was completed successfully.

ALSO WITH the current implementation using posix_spawnp(), can i somehow catch the return value of scp that I am performing? The reason why i have used this function is because i dont want another process to wait while this does the transfer!

Last edited by akshay_satish; 11-21-2012 at 12:00 AM.
 
Old 11-21-2012, 03:20 AM   #2
akshay_satish
Member
 
Registered: May 2011
Posts: 63

Original Poster
Rep: Reputation: Disabled
hi, i am able to get somewhere now... I just need one small help.. Would really appreciate your thoughts...
Code:
    char cmd[1024] = "";
    FILE *fptr;

    fptr = fopen("error.log", "w");

    if(fptr == NULL)
    {
        printf("\nFile does not exist\n");
        fflush(stdout);
    }
    snprintf(cmd, sizeof(cmd), "%s %s %s %s %s 2> error.log", *argv, argv[1], argv[2], argv[3], argv[4]);
    printf("\n\nAKSHAY: %s\n\n", cmd);
    fflush(stdout);

    ret = posix_spawnp(
        &pid,
        cmd,
        NULL, NULL, /* no fd handling or attrs */
        argv,
        NULL /* no environment */);
My problem is the file error.log is getting created but nothing really gets written within it ! I think my posix_spawnp parameters are incorrect. Kindly suggest the right syntax if its wrong....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading and writing to pipes, file descriptors, and file streams cmartin0 Programming 1 02-13-2012 04:03 AM
File descriptors with pipes kickarzt Linux - Newbie 5 06-06-2010 08:35 AM
Sony PSP file transfer inaccurate transfer progress stratotak Linux - Newbie 3 01-02-2010 04:49 AM
pipes and streams and one file viroos Linux - Newbie 2 11-07-2008 01:56 PM
Curious about open file handlers and pipes with a past problem helptonewbie Linux - Newbie 1 08-27-2008 04:49 AM


All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration