title: NSTask (whoami) to string, to NSTask (cp) failed - Swift
body: <p>I am trying to make a copy of the AddressBook of my Mac to a save place before archiving it. Here is my code :</p>
  
  <pre><code> // whoami
                  let whoam : NSTask = NSTask()
                  whoam.launchPath = "/usr/bin/whoami"
  
              // pipe whoami| NSString
                  let UltimPipe : NSPipe = NSPipe()
                  let UltimPipeLisible : NSFileHandle = UltimPipe.fileHandleForReading
                  whoam.standardOutput = UltimPipe
              // lancement
                  whoam.launch()
  
              // lecture de la sortie
                  let DonSortie : NSData = UltimPipeLisible.readDataToEndOfFile()
                  let Sortie : String? = String(data: DonSortie, encoding:
                      NSUTF8StringEncoding)
  
                  if Sortie == nil
                  {
                      print("Résultat de sortie non-valide")
                      let MonAlerte:NSAlert = NSAlert()
                      MonAlerte.messageText = "Aucun élement trouvé."
                      MonAlerte.informativeText = ""
                      MonAlerte.runModal()
                      exit(1)
                  }
  
                  let ligne : String = Sortie!
                  print (ligne)
  
                  let source = "/Users/"+ligne+"/Library/Application Support/AddressBook"
                  let destin = "/Users/"+ligne+"/Desktop/test/"
  
  
  //cp
                  let duTache : NSTask = NSTask()
                  duTache.launchPath = "/bin/cp"
                  duTache.arguments = [ "-r", source, " ", destin ]
                  print (duTache.arguments)
  
                  let ifcPipe : NSPipe = NSPipe()
                  duTache.standardOutput = ifcPipe
  
              // lancement
                  duTache.launch()
  </code></pre>
  
  <p>The returned error is :</p>
  
  <pre><code>usage: cp [-R [-H |...]
  </code></pre>
  
  <p>It look like I have a syntax problem, and, when I do a print of the arguments of duTache (print (duTache.arguments)), the answer is :</p>
  
  <pre><code>Optional(["-r", "/Users/username\n/Library/Application Support/AddressBook", " ", "/Users/username\n/Desktop/test/"])
  </code></pre>
  
  <p>Maybe if I remove the "\n" present after the username the operation could be completed? Does anyone knows how to do that?</p>
  
  <p>Thank you for reading my post.</p>