making archive with perl, when path is with spaces - perl

How can I use path with spaces in a perl script, running Archive commend?
Saying this is the command with the path I need:
C:\\"Program Files"\\7-Zip\\7z.exe a d:\\views\\"My views" d:\\"Public view"
Someone has an idea?

If you use the system command with multiple arguments, each of them is passed unmodified to the invoked program:
system 'C:\Program Files\7-Zip\7z.exe', 'a',
'd:\views\My views', 'd:\Public view';

Although it isn't a Perl question, you can use this syntax
"C:\Program Files\7-Zip\7z.exe" a target.zip "c:\path with spaces\example.pdf"
And if you need to call from a perl script
$cmd = q!"C:\Program Files\7-Zip\7z.exe" a target.zip "c:\path with spaces\example.pdf"!;
system $cmd;

Related

Perl SYSTEM command fails with "Bad file descriptor" when running via Jenkins

I have a simple system command to copy file from one folder to another:
my $cmd = "xcopy /Y c:\DBs\Support\db.bak c:\jenkins\workdir\sql-bak-files";
When I try to run the following system commands, all fails:
1. my $res = qx/$cmd/;
2. my $res = qx($cmd);
3. using back ticks
All tries returned the error: Error number -1, error message: "Bad file descriptor".
When trying to use system($cmd) the error was Error number 65280, error message: "No such file or directory".
This perl code is running via Jenkins (ver 2.190.1) and perl v5.26.0.
This problem started after migrating the code from mercurial to git, but I don't think it's related.
It worked before, but now always fail :(
A backslash has a special meaning in a Perl quoted string. It is used to escape the following character - to "turn off" any special meaning. If you want to use a backslash in a Perl quoted string, then you need to use another backslash to escape it.
my $cmd = 'xcopy /Y c:\\DBs\\Support\\db.bak c:\\jenkins\\workdir\\sql-bak-files';
Alternatively, Perl recognises forward slashes in Windows paths, so it might be easier to replace your code with this:
my $cmd = 'xcopy /Y c:/DBs/Support/db.bak c:/jenkins/workdir/sql-bak-files';
Note that in both cases I have replaced your double-quotes with single-quotes. This has no effect on your problem, but it seems strange to use double-quoted strings if you're not using any of their special characteristics (like the expansion of variables).
Update: To debug a problem like this, you can try printing the string.
$ perl -E'say "xcopy /Y c:\DBs\Support\db.bak c:\jenkins\workdir\sql-bak-files"'
xcopy /Y c:DBsSupportdb.bak c:jenkinsworkdirsql-bak-files

Equivalent for linux mkdir {fileA,fileB} in PowerShell

I'm just curios. Is there an equivalent for PowerShell that behaves equally to the liunx command listed in the title, i.e.
mkdir {folderA, folderB}
?
-- edit
the command listed above creates the folders "folderA" and "folderB" (just saw that I wrote file previously. Sorry, my fault) in the current working directory.
The mkdir command in PowerShell is a wrapper for the New-Item command. If you want to create multiple folders with a single command, then run:
mkdir c:\test,c:\test2;
Effectively, because of positional parameters in PowerShell, this passes the array c:\test,c:\test2 to the -Path parameter of the New-Item command.

7zip command line synthax using wildcard

Based on this source, the following should work for the 7zip command line tool:
7zG a -tzip "C:\20131024_archive.zip" "C:\archive" *20131024*
The goal is to zip all the files containing the date in the name. However, this is not working for me as it zips all the files without the date filter.
I've tried all sorts of variants without success. What am I doing wrong?
It turns out the date filter goes into the target filename like so:
7zG a -tzip "C:\20131024_archive.zip" "C:\archive\*20131024*"
Just use forfiles if your using windows 7. Type forfiles /? for more info. A think this will do what you want:
pushd C:\archive
forfiles /m "*20131024*" /c "7zG a -tzip C:\20131024_archive.zip #file"
I'm not sure this will work if the file name has spaces.

How do I change directory and run a file in that directory in powershell?

For example, i want to run cygwin.bat which is located in the c:/cygwin/ directory...
I tried the following but got an error:
cd c:/cygwin ./cygwin.bat
cd c:/cygwin and ./cygwin.bat are two different statements. You can execute them from the interactive console like so:
PS C:\> cd c:/cygwin
PS C:\cygwin> ./cygwin.bat
Or, if you really want to do it on the same line, then use a ; between them to indicate separate statements.
cd c:/cygwin ; ./cygwin.bat
best way is the way its always been
c:\cygwin\cygwin.bat
it's all you need to type
Try iex
$command = "cd c:/cywin"
iex $command

Powershell error in Executing NUnit test

This might sound silly but I have been trying to execute a NUnit test using powershell script, had several attempts but no hope. is there different format or do I need to add a plugin?
Any help would be appriciated...
Command = "c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe" /config=Release "C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
Output as below:
PS C:\tests> "c:\Program Files\NUnit2.4.8\bin\nunit-console.exe" /config=Release
"C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
You must provide a value expression on the right-hand side of the '/' operator.
At line:1 char:55 + "c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe" / <<<<
config=Release "C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
Thanks in Advance
You didn't put the part
/config=Release
inside your quoted command text.
Your command should probably look like
"c:\Program Files\NUnit 2.4.8\bin\nunit-console.exe /config=Release C:\projects\IntegrationTests\IntegrationTests.nunit" 2>&1
... i didn't check nunit-console.exe command line options, but i suppose you already tested if the nunit command works.
Sorry for the mess in the top dialog, proper code version below
& 'c:\Program Files\NUnit 2.4.\bin\nunitconsole.exe' /config=Release C:\Projects\IntegrationTests\IntegrationTests.nunit 2>&1