How do I change directory and run a file in that directory in powershell? - 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

Related

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.

Calling Patch.exe from Powershell with p0 argument

I'm currently trying to patch some files via PowerShell using Patch.exe
I am able to call the exe using the '&' command, but it doesn't seem to be reading my p0 input. I'm not an expert on PowerShell and any help would be appreciated!
here is what I am calling in PS:
$output = & "$scriptPath\patch.exe" -p0 -i $scriptPath\diff.txt
My error reads:
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
Which I can emulate by leaving out the p0 parameter on my patch file from commandline.
Here are some alternatives I've already tried:
#$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt"
#CMD /c β€œ$scriptPath\patchFile.bat” (where patchFile.bat has %~dp0patch.exe -p0 < %~dp0diff.txt, seems like powershell reads < as 0<, so there is an error there I think)
#GET-CONTENT $scriptPath\diff.txt | &"$scriptPath\patch.exe" "-p0"
#GET-CONTENT $scriptPath\diff.txt | CMD /c β€œ$scriptPath\patch.exe -p0”
Thanks!
Try:
$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt"
Patch.exe started in the wrong context and I solved this by using Push-Location / Pop-Location
Here is what my code looks like now
Push-Location $scriptPath
$output = & "$scriptPath\patch.exe" -p0 -i "$scriptPath\diff.txt"
Pop-Location
Keith also mentioned in one of his comments that you can use:
[Environment]::CurrentDirectory = $pwd
I have not tested this, but I assume it does the same thing (Keith is a powershell MVP, I am just a student).

How do I create an alias for a directory in ipython?

On Windows I want to create an alias for my working directory so I can quickly cd into it.
I have tried this command
%alias $UWHPSC echo 'c:/Users/xxxx/Documents/uwhpsc'
cd $UWHPSC
which gives the following error
[Error 2] The system cannot find the file specified: u'$UWHPSC'
c:\Users\xxxx\Documents\uwhpsc
%cd has a notion of bookmarks, which persist across IPython sessions:
%bookmark UWHPSC c:/Users/xxxx/Documents/uwhpsc
%cd UWHPSC
See the output of %bookmark? for more info.
Just define a normal Python variable, and then use it with a $ in the cd command:
UWHPSC = 'c:/Users/xxxx/Documents/uwhpsc'
cd $UWHPSC

making archive with perl, when path is with spaces

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;

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