copy with Process.execute

Post Reply
hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

copy with Process.execute

Post by hover27 » Wed Jan 13, 2021 9:59 pm

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

Padawan
Advanced member
Posts: 295
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: copy with Process.execute

Post by Padawan » Wed Jan 13, 2021 10:25 pm

Can you try this?
job.log(1, Process.stderr);

Stdout gives normal output, stderr error output

hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

Re: copy with Process.execute

Post by hover27 » Thu Jan 14, 2021 8:30 am

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

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: copy with Process.execute

Post by jan_suhr » Thu Jan 14, 2021 8:49 am

Can't you just do like this in Switch:
Snag_9f2a24b.png
Snag_9f2a24b.png (5.41 KiB) Viewed 973 times
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

Re: copy with Process.execute

Post by hover27 » Thu Jan 14, 2021 8:58 am

@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.

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: copy with Process.execute

Post by jan_suhr » Thu Jan 14, 2021 9:16 am

OK, so want to merge two files
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: copy with Process.execute

Post by jan_suhr » Thu Jan 14, 2021 9:18 am

With Switch Scripter you can read the file content from both files and merge that content in to a new file.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

Re: copy with Process.execute

Post by hover27 » Thu Jan 14, 2021 11:16 am

Ah, that's a good idea.
I will try this.

laurentd
Member
Posts: 36
Joined: Wed Mar 13, 2019 2:06 pm

Re: copy with Process.execute

Post by laurentd » Thu Jan 14, 2021 11:59 am

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
Laurent De Wilde, Solution Architect @ Enfocus

hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

Re: copy with Process.execute

Post by hover27 » Thu Jan 14, 2021 6:19 pm

@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().

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: copy with Process.execute

Post by jan_suhr » Thu Jan 14, 2021 7:30 pm

hover27 wrote:
Thu Jan 14, 2021 6:19 pm
@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().
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.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

hover27
Newbie
Posts: 14
Joined: Sat Apr 20, 2019 3:49 pm

Re: copy with Process.execute

Post by hover27 » Fri Jan 15, 2021 1:48 pm

jan_suhr wrote:
Thu Jan 14, 2021 7:30 pm

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.
That was my first thought also, but 'copy' is an internal DOS command. There is no separate path for it.

Post Reply