Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Run copy command in the background using vc++

Run copy command in the background using vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R raj1576

    Hi All I am using copy command to join two files. It works fine when I am using this in the command prompt But I want to run this command in the background using vc++. so please tell me how I run this command in the background. copy /b "first file path"+"second file path" "outfilepath"

    _ Offline
    _ Offline
    _Superman_
    wrote on last edited by
    #2

    You can use the system function to execute the command. But it is preferable to use the file operation APIs like CreateFile and WriteFile to achieve the same.

    «_Superman_» I love work. It gives me something to do between weekends.
    Microsoft MVP (Visual C++)

    R 1 Reply Last reply
    0
    • _ _Superman_

      You can use the system function to execute the command. But it is preferable to use the file operation APIs like CreateFile and WriteFile to achieve the same.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      R Offline
      R Offline
      raj1576
      wrote on last edited by
      #3

      Thanks for reply I try system command Its working fine but the command window is show. I want also hide this command window. actually i am joining mp3 file so thats why i am using copy command.

      _ 1 Reply Last reply
      0
      • R raj1576

        Thanks for reply I try system command Its working fine but the command window is show. I want also hide this command window. actually i am joining mp3 file so thats why i am using copy command.

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #4

        To hide the command window you will have to do a lot more work. You will need to use CreateProcess to start the command prompt (Cmd.exe) and specifying CREATE_NO_WINDOW in the dwCreationFlags parameter. If this doesn't work you can set the STARTF_USESHOWWINDOW flag in the STARTUPINFO structure and set its wShowWindow member to SW_HIDE. The copy command will need to be given as parameter to the Cmd.exe. Instead it will be easier to use the file APIs like CreateFile and WriteFile.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        R 1 Reply Last reply
        0
        • R raj1576

          Hi All I am using copy command to join two files. It works fine when I am using this in the command prompt But I want to run this command in the background using vc++. so please tell me how I run this command in the background. copy /b "first file path"+"second file path" "outfilepath"

          A Offline
          A Offline
          Adam Roderick J
          wrote on last edited by
          #5

          I dont think its better to use copy command, instead use Copy file API( [^]) Well if you still want to stick with your choice then :- 1. Use CreateProcess use CreateProcess with second parameter is command line argument([^]), where there is a optional structure STARTINFO([^]), having the wShowWindow to show or hide the window. 2. Use ShellExecute([^]) Eg:- NT/2k/XP/2k3

          ShellExecute( NULL, "open", "cmd.exe /C \"DEL /f /s /q c:\\check\\*\"", NULL, NULL, SW_HIDE );

          Win9x

          ShellExecute( NULL, "open", "command.com /C \"DEL /f /s /q c:\\check\\*\"", NULL, NULL, SW_HIDE );

          Величие не Бога может быть недооценена.

          R 1 Reply Last reply
          0
          • R raj1576

            Hi All I am using copy command to join two files. It works fine when I am using this in the command prompt But I want to run this command in the background using vc++. so please tell me how I run this command in the background. copy /b "first file path"+"second file path" "outfilepath"

            K Offline
            K Offline
            KingsGambit
            wrote on last edited by
            #6

            In addition to what others have mentioned, may be you can take a look at SHFileOperation() API as well. http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx[^]

            1 Reply Last reply
            0
            • _ _Superman_

              To hide the command window you will have to do a lot more work. You will need to use CreateProcess to start the command prompt (Cmd.exe) and specifying CREATE_NO_WINDOW in the dwCreationFlags parameter. If this doesn't work you can set the STARTF_USESHOWWINDOW flag in the STARTUPINFO structure and set its wShowWindow member to SW_HIDE. The copy command will need to be given as parameter to the Cmd.exe. Instead it will be easier to use the file APIs like CreateFile and WriteFile.

              «_Superman_» I love work. It gives me something to do between weekends.
              Microsoft MVP (Visual C++)

              R Offline
              R Offline
              raj1576
              wrote on last edited by
              #7

              Now I tried this char cmdpath[MAX_PATH] ={0}; cmdpath = "copy /b firstfilepath+secondfilepath outfilepath " CreateProcessA("cmd.exe", cmdpath, NULL, NULL, FALSE,NULL DETACHED_PROCESS , NULL, NULL, &sInfo, &pInfo); but this is not joining the file

              _ D 2 Replies Last reply
              0
              • R raj1576

                Now I tried this char cmdpath[MAX_PATH] ={0}; cmdpath = "copy /b firstfilepath+secondfilepath outfilepath " CreateProcessA("cmd.exe", cmdpath, NULL, NULL, FALSE,NULL DETACHED_PROCESS , NULL, NULL, &sInfo, &pInfo); but this is not joining the file

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #8

                cmd.exe itself has some command line parameters that you need to specify to execute internal commands.

                «_Superman_» I love work. It gives me something to do between weekends.
                Microsoft MVP (Visual C++)

                1 Reply Last reply
                0
                • A Adam Roderick J

                  I dont think its better to use copy command, instead use Copy file API( [^]) Well if you still want to stick with your choice then :- 1. Use CreateProcess use CreateProcess with second parameter is command line argument([^]), where there is a optional structure STARTINFO([^]), having the wShowWindow to show or hide the window. 2. Use ShellExecute([^]) Eg:- NT/2k/XP/2k3

                  ShellExecute( NULL, "open", "cmd.exe /C \"DEL /f /s /q c:\\check\\*\"", NULL, NULL, SW_HIDE );

                  Win9x

                  ShellExecute( NULL, "open", "command.com /C \"DEL /f /s /q c:\\check\\*\"", NULL, NULL, SW_HIDE );

                  Величие не Бога может быть недооценена.

                  R Offline
                  R Offline
                  raj1576
                  wrote on last edited by
                  #9

                  Thanks for reply can u explain how i use this copy command use in the shellexecute copy /b "firstfile.mp3"+"secondfile.mp3" "outputfile.mp3"

                  M 1 Reply Last reply
                  0
                  • R raj1576

                    Thanks for reply can u explain how i use this copy command use in the shellexecute copy /b "firstfile.mp3"+"secondfile.mp3" "outputfile.mp3"

                    M Offline
                    M Offline
                    Maximilien
                    wrote on last edited by
                    #10

                    I don't think you can merge MP3 files like that, they both have their own headers describing how is the data encoded (for example, you have 1 mp3 @ 320kbps and 1 mp3 @ 160kbps, what should the file be at the end ?) You will have to convert that to WAV, and then you will be able to copy one WAV at the end of the other and after that reconvert to MP3 (and loosing precision and data in all the conversions). M.

                    Watched code never compiles.

                    D 1 Reply Last reply
                    0
                    • R raj1576

                      Now I tried this char cmdpath[MAX_PATH] ={0}; cmdpath = "copy /b firstfilepath+secondfilepath outfilepath " CreateProcessA("cmd.exe", cmdpath, NULL, NULL, FALSE,NULL DETACHED_PROCESS , NULL, NULL, &sInfo, &pInfo); but this is not joining the file

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      raj1576 wrote:

                      cmdpath = "copy /b firstfilepath+secondfilepath outfilepath "

                      This will not work. You either need to initialize cmdpath with this string literal, or use strcpy().

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "Man who follows car will be exhausted." - Confucius

                      1 Reply Last reply
                      0
                      • M Maximilien

                        I don't think you can merge MP3 files like that, they both have their own headers describing how is the data encoded (for example, you have 1 mp3 @ 320kbps and 1 mp3 @ 160kbps, what should the file be at the end ?) You will have to convert that to WAV, and then you will be able to copy one WAV at the end of the other and after that reconvert to MP3 (and loosing precision and data in all the conversions). M.

                        Watched code never compiles.

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        Maximilien wrote:

                        I don't think you can merge MP3 files like that, they both have their own headers describing how is the data encoded (for example, you have 1 mp3 @ 320kbps and 1 mp3 @ 160kbps, what should the file be at the end ?)

                        That's what I thought too, but then he did state, "I am using copy command to join two files. It works fine when I am using this in the command prompt." :confused:

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "Man who follows car will be exhausted." - Confucius

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups