CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: using linux commands in C++ code

    I don't have that much Linux experience but I doubt that it will be any significant change in speed. After all redirecting the output using the > is pretty much the same thing as redirecting it using code. Anyway, if you want to test it adding those lines in main() should be sufficient.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  2. #17
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    Alright. Thanks S_M_A. Let me try this.

  3. #18
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    S_M_A it worked in C++ code and was much faster than it was when written explicitly on command line . Thanks

  4. #19
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    Someone suggested me this example "http://www.cplusplus.com/reference/iostream/ios/rdbuf/" which I found a bit easier and it worked as well but not when I tried to use it with the output of this command

    Code:
    system("diff /home/test1.txt /home/test2.txt");
    Do you have any idea why? it still prints the output on to the screen and not to a file.

  5. #20
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: using linux commands in C++ code

    Hm sounds like a system call does not run in an exact copy of the parent process environment. Amazing also that there was a difference. You learn something new every day...

    I guess you could change the diff call to redirect the output? Try that and I'll browse around abit to check if there's some other way to do it.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  6. #21
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    Thanks S_M_S

    could you please write to me a line of code for changing the diff call to redirect the output?

  7. #22
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: using linux commands in C++ code

    Nope, I didn't find any new info regarding this.

    You redirect just as you've done before by using > on the command line.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  8. #23
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    Alright Thanks a lot any way.

    I have just found a code which is I think written in perl. Could you please tell me the meaning of each of these lines because I ran this code and it worked exactly what I needed

    Code:
    #!/bin/bash
    
    counter=1
    exec 3< /usr/local/test1.txt
    
    while read -u3 line
    do
    grep "$line" /usr/local/test1.txt2>/dev/null
    if [[ $? -eq 1 ]]
    then
    echo "Line $counter is not present in Naginas_Exp_0206_non_dupCME file!!!"
    fi
    (( counter += 1 ))
    done

  9. #24
    Join Date
    Feb 2002
    Posts
    4,640

    Re: using linux commands in C++ code

    Quote Originally Posted by heidiK View Post
    Alright Thanks a lot any way.

    I have just found a code which is I think written in perl. Could you please tell me the meaning of each of these lines because I ran this code and it worked exactly what I needed

    Code:
    #!/bin/bash
    
    counter=1
    exec 3< /usr/local/test1.txt
    
    while read -u3 line
    do
    grep "$line" /usr/local/test1.txt2>/dev/null
    if [[ $? -eq 1 ]]
    then
    echo "Line $counter is not present in Naginas_Exp_0206_non_dupCME file!!!"
    fi
    (( counter += 1 ))
    done
    That's a bash script, not PERL. Just type 'man bash' on your *NIX terminal.

    Viggy

  10. #25
    Join Date
    Oct 2010
    Posts
    106

    Re: using linux commands in C++ code

    Thanks Viggy

  11. #26
    Join Date
    Apr 2011
    Posts
    1

    Re: using linux commands in C++ code

    Here you can check out the most used linux commands .

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured