Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-20-2012, 08:54 PM   #1
Registered: May 2011
Posts: 63

Rep: Reputation: Disabled
file transfer using pipes

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

ret = waitpid(pid,&status,0);
if(ret != pid) {
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);
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-->

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-20-2012 at 11:00 PM.
Old 11-21-2012, 02:20 AM   #2
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...
    char cmd[1024] = "";
    FILE *fptr;

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

    if(fptr == NULL)
        printf("\nFile does not exist\n");
    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);

    ret = posix_spawnp(
        NULL, NULL, /* no fd handling or attrs */
        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....


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 03:03 AM
File descriptors with pipes kickarzt Linux - Newbie 5 06-06-2010 07:35 AM
Sony PSP file transfer inaccurate transfer progress stratotak Linux - Newbie 3 01-02-2010 03:49 AM
pipes and streams and one file viroos Linux - Newbie 2 11-07-2008 12:56 PM
Curious about open file handlers and pipes with a past problem helptonewbie Linux - Newbie 1 08-27-2008 03:49 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:54 AM.

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