copy with Process.execute
copy with Process.execute
Hi,
I want to copy files with Process.execute()
The reason therefor is, that I want to use some parameters, which aren't possible with Switch internal copy functin but with windwos copy.
(to copy two files together)
I tried to do this:
path1 = "\"C:\\folder1\\folder2\\myFile.txt\"";
path2 = "\"C:\\folder1\\folder2\\myFileNEW.txt\"";
var theCommand = 'copy ' + path1 + ' ' + path2 ;
job.log(1, theCommand);
Process.execute(theCommand) ;
job.log(1, Process.stdout);
I get the message:
Failed to run external process: copy C:\folder1\folder2\myFile.txt C:\folder1\folder2\myFileNEW.txt
Does anybody know, what is my mistake?
Thx
hover
I want to copy files with Process.execute()
The reason therefor is, that I want to use some parameters, which aren't possible with Switch internal copy functin but with windwos copy.
(to copy two files together)
I tried to do this:
path1 = "\"C:\\folder1\\folder2\\myFile.txt\"";
path2 = "\"C:\\folder1\\folder2\\myFileNEW.txt\"";
var theCommand = 'copy ' + path1 + ' ' + path2 ;
job.log(1, theCommand);
Process.execute(theCommand) ;
job.log(1, Process.stdout);
I get the message:
Failed to run external process: copy C:\folder1\folder2\myFile.txt C:\folder1\folder2\myFileNEW.txt
Does anybody know, what is my mistake?
Thx
hover
Re: copy with Process.execute
Can you try this?
job.log(1, Process.stderr);
Stdout gives normal output, stderr error output
job.log(1, Process.stderr);
Stdout gives normal output, stderr error output
Re: copy with Process.execute
the script does not go to the line with the log, so there is no message/log entry for job.log(1, Process.stderr)
when switch tries to execute Process.execute(theCommand)
there is a message from with type = Error and Module = Control:
Failed to run external process: copy C:\folder1\folder2\myFile.txt C:\folder1\folder2\myFileNEW.txt
when switch tries to execute Process.execute(theCommand)
there is a message from with type = Error and Module = Control:
Failed to run external process: copy C:\folder1\folder2\myFile.txt C:\folder1\folder2\myFileNEW.txt
Re: copy with Process.execute
Can't you just do like this in Switch:
Re: copy with Process.execute
@jan_suhr
no, that is not what I need.
I need to copy two files together.
That is only possible with the internal command copy.
With the parameters of copy, I can copy two files into one file.
That's why I need to do it with Process.execute() and the copy command.
no, that is not what I need.
I need to copy two files together.
That is only possible with the internal command copy.
With the parameters of copy, I can copy two files into one file.
That's why I need to do it with Process.execute() and the copy command.
Re: copy with Process.execute
OK, so want to merge two files
Re: copy with Process.execute
With Switch Scripter you can read the file content from both files and merge that content in to a new file.
Re: copy with Process.execute
Ah, that's a good idea.
I will try this.
I will try this.
Re: copy with Process.execute
Here is another possibility:
This is the right command: copy /b path1 + path2 outputPath
You can use the Execute command element and point to a .bat file
Output: file at path
If one file is the Switch job and the other file is a fixed file (eg when you add a header to your file):
Arguments: "%1" "%2"
Bat file content: copy /b “fixedFilePath” + %1 %2
If the two files are variable, first assemble them in a job folder, then use this:
Arguments: "%1\[Job.NestedName:Index='2',After=' ']" "%1\[Job.NestedName:Index='3',After=' ']" "%2"
Bat file content: copy /b %1 + %2 %3
This is the right command: copy /b path1 + path2 outputPath
You can use the Execute command element and point to a .bat file
Output: file at path
If one file is the Switch job and the other file is a fixed file (eg when you add a header to your file):
Arguments: "%1" "%2"
Bat file content: copy /b “fixedFilePath” + %1 %2
If the two files are variable, first assemble them in a job folder, then use this:
Arguments: "%1\[Job.NestedName:Index='2',After=' ']" "%1\[Job.NestedName:Index='3',After=' ']" "%2"
Bat file content: copy /b %1 + %2 %3
Laurent De Wilde, Solution Architect @ Enfocus
Re: copy with Process.execute
@laurentd
that is exactly what I want to do.
Thank you, good idea.
It seems, that Switch isn't able to process the copy command with Process.execute().
that is exactly what I want to do.
Thank you, good idea.
It seems, that Switch isn't able to process the copy command with Process.execute().
Re: copy with Process.execute
It is probably because it isn't in the path for Switch to find it. A Switch Script is running in it's own environment and you have to adjust the path setting.
Re: copy with Process.execute
That was my first thought also, but 'copy' is an internal DOS command. There is no separate path for it.