Perl in Windows 8 - windows

I am trying to get Strawberry perl running on my windows 8 machine. This is my first attempt ever to use perl and I am going through the readme file to try and get it up and running. At the moment i have got as far as typing
c:\>perl
and i get access denied message. Am i misunderstanding the readme or do i need to make some further adjustments to get it to work?
The instrustions for the readme are
1. run any perl script by launching
c:\> perl c:\path\to\script.pl
i have also tried
c:\>perl c:\perls\ex1.pl
where perls is the folder on C: in which the script ex1 is located. Also get access denied message.

Posting comment as answer.
The command
c:\>perl
in the windows cmd shell is an instruction to redirect the output of the command c:\ to a file named perl. The > character is the one that does that.
I was going to say that it fails because you probably have a directory named perl there, but I notice on my system that it fails even though I have no such directory.
The problem is that the readme had included the prompt in their sample command. The default prompt in windows cmd looks like that: C:\> So, like I mentioned in the comments, the command you need to run perl is simply perl. For example:
perl -e "print 'Hello world!'"

It could be either the fact that Perl isn't in your PATH, or permissions issue.
If it's the PATH, to troubleshoot and fix:
Find the directory where you installed Perl (say, "c:\program files\strawberry\perl\bin\" as an example)
Run Perl as full path: `"c:\program files\strawberry\perl\bin\perl c:\perls\ex1.pl".
If that works, you will simply need to add Perl's directory to PATH variable, so that running "perl" without a path will search for it in that directory. To do that, here are the references:
Window add Java to Path
https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them
http://www.itechtics.com/customize-windows-environment-variables/
If it's permissions, here's a reference: http://windows.microsoft.com/en-us/windows7/how-do-i-open-a-file-if-i-get-an-access-denied-message

Related

How to run zookeeper.sh file in windows

I am following this tutorial where i have to run this command in order to start the zookeeper server.
./bin/zookeeper-server-start.sh config/zookeeper.properties
But the problem is this command is not working properly. I found that .sh file is bash file that required cygwin. I have installed it and then run command like this
C:\cygwin64\bin\bash.exe ./bin/zookeeper-server-start.sh config/zookeeper.properties
But it is showing:
I can confirm that in bin directory the file is exsits. what i am doing wrong?
Here is my directory snapshot from where i running the command:
Note: I have successfully tested bin/windows zookeeper bat file but i want to run it through .sh file as the kafka security tutorial which i am following using this.
From your screenshot, I conclude that you are using Cygwin. So, please add the cygwin tag to your question.
As you can see from the error message, the command dirname is not found by bash, so assuming that your Cygwin installation is not broken, I assume that the PATH is not set correctly; in your setup, dirname.exe should be in C:/cygwin64/bin (please verify this).
Your usage of bash.exe is a bit unusual in that you run it directly from a Windows cmd prompt. The more common way would be to use it from the 'Cygwin Terminal', which you get created a Windows-link to, when installing Cygwin, or to use another suitable Terminal program; I'm using for instance mintty for this task (also available via the Cygwin installer).
Having said this, it is possible to run bash.exe in the way you are doing it, but you then have to ensure, that at least the PATH is set up correctly. One possibility to do this, is to add C:\cygwin64\bin to your Windows PATH, but this has the drawback, that some commands have the same name in the Windows world and in Cygwin, though they serve a completely different purpose, and this will bite you sooner or later. Another problem is that at some point, you will rely on other bash specific setups besides the PATH.
A better way to accomplish your goal is IMO to ensure, that the system wide bash-initialization files are sourced by bash. If I have to run the script from a Windows cmd prompt, I would run it by
C:\cygwin64\bin\bash.exe --login YOURSCRIPT
This will read the file (in your setup) C:\cygwin64\etc\profile before running YOURSCRIPT, so you can check, that the PATH is correctly set there, by looking at this file. In a default installation, this should be the case.
After having read this file, it will try to read the file .bash_profile in your Cygwin HOME directory, so if you need additional settings for your (non-interactive) bash-scripts, create this file and put your settings there.

Perl not running in Windows 10

I've just downloaded ActivePerl for Windows 10 on my 64 bit laptop, but when I go to the command prompt, perl -v fails unless the directory is C:\Perl64\bin in which case it tells me that I have Perl 5.20.2 Copyright Larry Ullman etc, but if I try and open perl files anywhere, nothing happens, if I run perl.exe it just shows me a command window with a flashing bar and nothing happens, and when I try and run .pl programs in Eclipse it tells me predictably that because perl-v failed it won't run.
What can I do to get .pl files running?
You must create a file association between the .pl file extension and the Perl runtime.
At a command prompt type the following.
assoc .pl=PerlScript
ftype PerlScript=c:\perl\bin\perl.exe %1 %*
Choose perl.exe or wperl.exe, depending on your need to get a visible command window.
To get perl to be recognized, you must add C:\Perl64\bin to the PATH environment variable. Go to Control Panel > System > Advanced System Settings > Environment Variables. Edit the line containing PATH in the top box marked User variables for , and add ;C:\Perl64\bin (note the semicolon) to the end. Be sure not to corrupt anything that's already there.
installing perl in windows 7

In perl how to get current directory path of any process?

In Perl, I want to get the current working directory of any process.
e.g. We have command "pwdx" in unix which gives current working directory of a process.
I want similar "pwdx " in perl.
Please let me know any Perl command which gives me current working directory of a process.
Note: I am on Windows platform and not in Unix platform.
Regards,
Amol
You could get the details about a process (along with current working directory) with wmic or handle shell commands, as described in this question: windows batch command to determine working directory of a process
Then you could use that command with backticks (``) to get the output and use a regex to get the current working directory.
Note: I'm not on windows so I can't test the commands.
You might look at Win32::Process modules.

How to create ls in windows command prompt?

I want to use ls in windows command prompt and make it run the dir command.
How can I do that?
You can solve this question with one simple command:
echo #dir %* > %systemroot%\system32\ls.bat
Make sure you run cmd.exe as admin first if you are on vista and up
You could:
create a batch file called ls.bat and have it contain the dir command only
add the directory where the ls.bat file exists to your PATH environment variable
You could then execute ls from a command prompt.
Its an old question but for the record:
http://gnuwin32.sourceforge.net/packages/coreutils.htm
Gives you ls and a whole lot more!
Easiest way I have found is:
Install Git for Windows
Add the bin directory of Git to your Path variable. Mine was located in C:\Program Files\Git\usr\bin.
Start a command prompt and enjoy ls in all its glory.
I have a solution but it's dirty:
Create a file named ls.bat containing only "dir".
Put it in C:\windows\system32 (or any directory in PATH env var).
That (should) works!
Edit: Something more consistent: https://superuser.com/questions/49170/create-an-alias-in-windows-xp
If you have Node.js installed on your system, you can install it from Cash, a library I wrote for Linux commands on Windows:
npm install cash-ls -g
Windows command prompt for Vista/7 will allow NTFS symbolic links, run cmd.exe as administrator then:
mklink ls %System%\dir.exe
Then set up your PATH environment variable to include the location of the link you just created.
If you want more than just the 'ls' command, you should look into cygwin.
EDIT- Just realized dir.exe is not a separate program, so this doesn't really work. But mklink and cygwin are good things to know about.
If you just want to have cmd recognize ls as an alias for dir, you can use the doskey command (from this answer on superuser).
This does not change the original command line parameter handling of the dir command.
+1 on the post above suggesting to install git for windows and add the directory bin to your path variables.
Another way I got touch, ls, and a lot of other UNIX commands working in cmd.exe on my Windows 8 and Windows 7 machines.
Go to the following site to install Cygwin
https://www.cygwin.com/install.html
Install the 32 or 64 bit version for your system. The default settings and packages should include what you need so you don't have to change anything once you get to the packages screen.
After installation, copy the Cygwin folder path to your environment path variables. For example; if you installed cygwin to C:\Cygwin, you will add the following to your environment system path variables:
;C:\Cygwin\bin
On my system I installed the 64bit version and the default folder name and path was C:\cygwin64. So i added the following to my system environment path variables:
;C:\cygwin64\bin
Restart your terminal if it's open. Then type ls and you'll see a directory listing.
See the following if you are not familiar with setting PATH environment variables:
Superuser Link 1
Superuser Link 2
my ls.bat was below
#dir %*
that can transfer cli args
ls /b
ls /w
put it in %windir% or any directory in your %PATH% variable.
Just make sure you save the file with ANSI encoding :)
you could also use cygwin and just use the ls command directly along with all the other unix command line tools you might be used to.
I recommend the following recipe.
Use DOSKEY and $* to create your ls command.
Make the command persistent by recording it in a .bat/.cmd file and add the path of the file to registry.
For example, your command may look like
DOSKEY ls=dir
DOSKEY sublime="C:\Program Files\Sublime Text 2\sublime_text" $*
$* is useful for commands that take on arguments. For example, here I like to be able to do sublime my_code.c.
The registry for cmd is at HKEY_CURRENT_USER -> Software -> Microsoft -> Command Processor. Create a string valued entry called AutoRun with the full path of the file (not the containing folder) such as %USERPROFILE%\custom_command.cmd. Then each time cmd is run, your command will be loaded!
You can add more useful stuffs to the batch file too. See here for an example template.
Another solution that worked for me is to use UnxUtils, which adds multiple utilities from executable files (including ls, sed, and grep).
To use: download source code. Unzip. Add the UnxUtils\usr\local\wbin path to the Windows PATH variable. Start a new CMD instance.
The most easiest way is
install git
add C:\Program Files\Git\usr\bin to your path variable
now you can use ls
Someone who uses Linux Subsystem for Windows could call ls from the Linux bash. The following Command creates the ls Command in System32:
echo #bash -c "ls %*" > %systemroot%\system32\ls.bat
(The Linux Subsystem feature must be enabled/installed first)
You could follow this guide:
https://gist.github.com/vladikoff/38307908088d58af206b
TL;DR: pass /K path/to/custom/init_cmd.bat to your "shell startup" command.
I'm using ConsoleZ as my shell wrapper, so in my case I can find the setup option in "tabs", then I set the shell path to "C:\Windows\System32\cmd.exe "/K C:\cmd_init.bat""
like this.
Where C:\cmd_init.bat is the batch script containing my macros, here's what I would go for:
#echo off
doskey ls=dir /b
rem other macro stuff..
Sorry for formatting and other mistakes, this is my first time answering here.
I hope it helps!
Create an alias in .bat or .cmd file using doskey key:
#echo off
title "ls command cmd bar"
doskey ls=echo off $T dir $* $T echo on
Enjoy =)
Surely ls would not work as a unix command for the batches. If you check %1 for -l or -a etc. and all combinations of them, it would work...
Here is my C# source code and binary.
Just add ls.exe somewhere and add the path to the path environment variable.

cywin bash script command not found when called from batch

#!/bin/bash
echo "Testing"
cd "/cygdrive/x/Internal Communications/Riccardo/"
filename=htdocs-`date +%A`.tar.gz
tar cvzf $filename "/cygdrive/c/Program Files/Zend/Apache2/htdocs"
The above script is working when it is called inside cygwin console, but when I try to call it from a batch file I get "command not found" for date and tar command. I think that bash.exe does not have the PATH set up.
I need to run that script from that batch file because I want to add the script to the task scheduler.
As has already been said, you need to add the Cygwin binaries to your path. To do so, right click on "My Computer", click "Properties", then "Advanced", then "Environment Variables".
Create a new environment variable with name "CYGWIN_HOME" and value "C:\cygwin" (or wherever you installed cygwin. The default location is "C:\cygwin\" so this should probably work for you).
Then edit the environment variable named "PATH", and tack on the following to the end:
;%CYGWIN_HOME%\bin;%CYGWIN_HOME%\sbin;%CYGWIN_HOME%\usr\bin;%CYGWIN_HOME%\usr\sbin;%CYGWIN_HOME%\usr\local\bin;%CYGWIN_HOME%\usr\local\sbin
Close your command prompt, then reopen it. The cygwin binaries should now be available. You can double-check this by typing "which bash". It should report the location of your bash executable.
FWIW, Cygwin has cron.
Are you calling your script like this?
bash --login -i ./myscript.sh
Put your cygwin bin directory (likely C:\cygwin\bin) on your PATH environment variable.
This would also give you the benefit of being able to use commands like tar, ls, rm, etc. from a regular console windows and not just a Cygwin console.
If this script is invoked from a Windows command shell, the first line will result in an error since #!/bin/bash is not a recognized Windows command and # is not a valid comment delimiter in a batch file.
So, the bottom line is that this script runs as a regular batch file rather than from within Cygwin's bash. As noted by matt b, you likely do not have the Cygwin executable path in your PATH environment variable. Without this, the batch file cannot find the Cygwin utilities (tar and date).
I just had this problem.
Editing the environment variable works great. But if you are have no admin rights you canĀ“t do that.
In this case you can execute your commands by using the absolute path like:
/usr/bin/tar cvzf $filename
/usr/bin/cat $filename
If you do so your bash script works even if you call it from a batch file.

Resources