How do I get my Windows7 symlink to execute from command line? - windows

I have a couple of batch files I want to use regularly, so I decided I would drop them as symlinks into a binaries folder in my path. The idea being that I would use them like I would any other command, without having to change directories. E.g.
> odbimport -u User -f filename
where odbimport is my symlink to the batch file odbimport.bat.
The process I used to make the symlinks is as follows:
C:\Users\user>mklink C:\utils\odbimport C:\util-files\odbimport.bat
symbolic link created for C:\utils\odbimport <<===>> C:\util-files\odbimport.bat
C:\Users\user>path
Path=C:\....;C:\utils\
C:\Users\user>where odbimport
C:\utils\odbimport
From what I've seen, it looks like I've made the symlink, and the path knows where to find it.
However, after I've made my symlink and attempt to execute, I get:
C:\Users\user> odbimport -u me -f somefile
'odbimport' is not recognized as an internal or external command,
operable program or batch file. "
I've been looking for an answer to this with no success. Everything I find seems to deal more with how to create working symlinks than addressing my issue. The closest thing I found was this. This is essentially my question, except kinda backwards because I don't really want to run the symlinks from Windows Explorer. I have also tried adding .LNK to my PATHEXT variable as in this question.

Add .bat extension to the symlink you create because on Windows .bat extension is necessary to tell the system it's actually an executable batch file. You will still be able to run the file by typing its name only.
mklink C:\utils\odbimport.bat C:\util-files\odbimport.bat
NTSF hardlinks can be used when source and target are on the same volume, the advantage is that such clones may be executed from Windows Explorer unlike symlinks:
mklink /h C:\utils\odbimport.bat C:\util-files\odbimport.bat
fsutil hardlink create C:\utils\odbimport.bat C:\util-files\odbimport.bat

Related

Cannot find file to delete via git bash, but it shows up in file explorer

I started to learn git yesterday, and I made a mistake when I created ssh key as the first image shows.
I tried .bat delete way and dos del command, still cannot delete file named cd ..
The prompt said cannot find file. The attribute of file size is 0 byte.
How to delete this file?
I managed to delete "cd .." in a CMD Windows with <path/to/git>\latest\usr\bin in %PATH%. That gives me access to rm.exe.
vonc#VONCAVN7 C:\test
> where rm
D:\prgs\git\latest\usr\bin\rm.exe
I had:
vonc#VONCAVN7 C:\test
> dir /x
Volume in drive C is test
Directory of C:\test
08/08/2017 07:11 <DIR> .
08/08/2017 07:11 <DIR> ..
08/08/2017 07:11 0 cd ..
With that, I typed:
vonc#VONCAVN7 C:\test
> rm cd*
And the file cd .. was gone
As commented by eryksun,
rm.exe isn't a Linux app. It uses msys-2.0.dll, which links with Windows API functions from kernel32.dll and native NT system calls from ntdll.dll.
In this case it's how it bypasses the Windows API to make direct system calls that solves the problem: NtOpenFile (open the directory to list it and the "cd .." file to delete it), NtQueryDirectoryFile (list the directory), and NtSetInformationFile (set the file's delete disposition).
As eryksun commented, the pure Windows syntax (meaning, it does not need a Git Linux-like command like rm) would have worked too:
del "\\?\C:\test\cd .."
See "What does \\?\ mean when prepended to a file path".
That will disable all string parsing and send the string that follows it straight to the file system.
Look into the properties of the file. There you may find file location. Go to that location and delete from there.
And see which type of file is it. I mean, it may be a system file, and if it is, system will not allow you to delete it. Open explorer as administrator and then try deleting it.

Windows CMD Shorten file path

I got Gnu Utilities that adds the command sed to windows, but to use it I have to type:
C:\ProgramFiles\GnuWin32\bin\sed.exe <args>
How do I shorten this to just sed <args>?
To run an executable without a full path, it needs to be either in the current directory, or in the PATH environment variable. In the CMD prompt, there are several ways to do this.
The first way is to put C:\ProgramFiles\GnuWin32\bin in your PATH variable, which makes every program in that directory available without a full path.
set "PATH=%path%;C:\ProgramFiles\GnuWin32\bin"
This updates PATH in the current command prompt. If you need to set it for other CMD windows, see How to persistently set a variable in Windows 7 from a batch file?
The second method is to have sed.exe in the current directory. The most obvious way to do that is to change directories.
cd C:\ProgramFiles\GnuWin32\bin
sed
Or you can copy it to your current directory.
copy C:\ProgramFiles\GnuWin32\bin\sed.exe .\
sed
(This works with sed.exe because it's a self-contained utility. Don't try this with a Windows application like excel.exe)
Finally, you can create a "redirect" somewhere in the current directory or the path.
>.\sed.bat echo C:\ProgramFiles\GnuWin32\bin\sed.exe %*
This creates a batch file in the current directory called sed.bat that calls the full sed.exe. You can drop this file into any directory in your PATH.
mklink .\sed.exe C:\ProgramFiles\GnuWin32\bin\sed.exe
This creates a symlink to the sed.exe in the current directory, much like a symlink in Unix or a shortcut in Windows.

How to start an application in a given directory, using other as its working dir?

For a system we are deploying for our customer we need to run the setup executable from %temp% and have it use for the installation, files in another directory.
This cannot be solved at the application level.
So, basically what I need it to somehow "cheat" the setup.exe located at %temp% to think it ran under another directory.
Any ideas?
I tried doing pushd & popd, that doesn't work because the OS tries to call setup.exe from the data files' directory, not setup.exe.
I also tried calling setup.exe by running a bat from the data files directory, that basically calls it by doing:
%temp%\setup.exe
doing:
cd %temp%
setup.exe
also failed
cd %files_dir%
%temp%\setup.exe
But
1) it's up to setup.exe to use current dir or not. So this command sequence can have no effect.
2) current dir can be changed at any moment (e.g. when system Files Open dialog is called).
You can try to create shrtcut of files in %temp% dir and use them instead of files. Maybe you'll need to play around with file extensions.

Location of windows command prompt command files

In Unix, the terminal commands are in /etc folder. Similarly, I'd like to know where the command files of Windows are located eg., mkdir, cd, etc. Thanks in advance.
You can use where to find where the executables are located.
Some as #sb9 said, are not separate exe's and they are built in. Using where you can find out if they have their own exe file or not.
where ftp
where at
where cd
In this case cd will error as it is built in.
Some commands are located in windows\system32, and some others (like mkdir and cd) are built in internally into the shell cmd.exe, so you won't find them on the hard disk.

Windows cmd: Copy over entire directory *including* parent directory. Solution without specifying same parent directory name

In Windows, how do you copy an entire directory, INCLUDING the parent directory folder?
For instance, let's say we have the directory c:\Folder and want to copy it over to d: .
The only way right now would be:
xcopy /E c:\Folder d:\Folder
Is there a way to do this without specifying the same end directory (Folder)?
I'm told that an application called RoboCopy can do it, however, I believe it's part of a series of server 2003/2008 tools -- I can't speak to its capabilities or whether it will work on your version of Windows. That said, there are a set of tools (basically UNIX commands ported to DOS) located here that will do what you need -- specifically the "cp" command. My apologies for not being able to assist further.

Resources