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

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.

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.

installed program "cppcheck" but command "where cppcheck" (on windows command line) can't find anything

I downloaded and installed the program "cppcheck" (http://cppcheck.sourceforge.net/).
This program has both a GUI (which I can access without problems) and a command line interface.
However, when I go to the windows command prompt and type "where cppcheck", nothing can be found.
Am I crazy? Or is the command line interface for cppcheck only accessible on Unix systems?
Since I usually don't work with Windows, I didn't realise that the "where" command just looks in the current folder and child folders of the current folder. That's why I didn't get any results.
You have to add it in the environment variables since the cppcheck installer does not add it automatically. This way you can use the where command from any folder as it also checks the environment variables too.

Perl in Windows 8

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

How to create and execute a file full of commands on Windows command prompt?

Example:
In Linux we can put the desired commands in a file and give it executable permissions. This helps us to actually run the file on the terminal and thus all the commands inside the file get automatically executed.
How to achieve this on Windows XP?
Same thing, but it's called a batch file, extension is .bat. You can also double-click to run these. This site is a great resource.

Any way to interpret a command without running cmd.exe?

I am looking for a way to run an executable or a script without getting cmd.exe to do it for me. Currently I'm launching a process using cmd.exe /C <command>, which I need to do the following things for me:
Look for the executable file in the current directory and PATH
Interpret PATHEXT to permit extension-less script commands
Interpret file associations to, e.g., run the python interpreter when I tell it to run blah.py.
I don't need to be able to run any of the "built-in" commands, like "dir".
Is it possible to avoid using cmd.exe without essentially re-implementing all of the above functionality? There must be some sort of shell API to do the above things, right?
ShellExecute should do exactly what you want - you can use it to launch an executable or a file (which is then opened with the standard application),
http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx
Take a look at System.Diagnostics.Process.Start( appName, args) .
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx and about the shell, have you looked it: http://msdn.microsoft.com/en-us/library/bb773177(v=vs.85).aspx ?

Resources