Running batch file from network share (vmware shared folder) in cygwin - batch-file

I'm having some problems with cygwin and a mapped network drive. My setup is kind of convoluted to deal with some limitations with our corporate VPN. I'm running a Windows 10 VM under VMware Fusion with a shared folder from my Mac host which is mapped to a network drive in Windows. The reason is b/c I access a remote Git repo using a VPN connection that leverages a browser plugin that unfortunately is only working from Safari currently. I need to run git commands from the Mac host but the project's build/development environment is Windows. The VPN browser plugin fails to install in any of the browsers under Windows. Hopefully a temporary problem but one I must workaround for now.
From my cygwin environment the mapped drive does not show up under /cygdrive, possibly b/c it's a shared folder with hgfs file system type. I'm able to mount the shared folder but when I try to run a batch file from the cygwin environment I get the following error:
./OpenCommandPrompt.bat
'\\vmware-host\Shared Folders\grant\Projects\lts\Product'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
The system cannot find the path specified.
'setenv.bat' is not recognized as an internal or external command,
operable program or batch file.
'setclasspath.bat' is not recognized as an internal or external
command, operable program or batch file.
C:\Windows>
It doesn't like the UNC path. I'm able to run the command fine from a PowerShell using the mapped drive letter but no luck from cygwin. My desire is to run the VM headless and access the Windows environment over SSH from my host so I'd like to get this working from the cygwin environment if possible. Any suggestions?

I was able to fix my issue by creating a simple script that I execute from my .bash_profile. I basically check for existence of the /cygdrive/h folder and if it doesn't exist I execute the script.
#!/bin/bash
net use H: '\\vmware-host\Shared Folders\share'
I tried to map the drive from Windows but all attempts to do so failed to register the drive mapping under the /cygdrive folder in cygwin. That was the issue I was trying to overcome. Once I had the mapped drive under /cygdrive, I was able to execute all the batch scripts.
To be honest, I'm still not sure why mapping the drive from Windows does not register it cygwin. The reverse is also true: if I execute the net command from the terminal, it does not register in Explorer.

Related

How to get vscode-remote-ssh extension connects via git bash in windows?

I have vs code configured to use the git bash as a terminal in windows 7.
"terminal.integrated.shell.windows": "C:\Program Files\Git\bin\bash.exe"
I have enabled SSH key based authentication to remotely access a host. All this works fine from within the terminal in VS Code.
However, when using the vscode-remote SSH extension to connect to host I get an error because it tries to connect using "The terminal process command 'cmd.exe'" instead of git bash.
I've checked my terminal settings configuration in vs code and it points to git bash.exe
I've used the terminal extension in vs code and it opens a git bash and successfully connects to the host
Is there a setting that I'm missing to force Remote-SSH to use the git bash for the connection?
JerryL's answer lead me to realize, that I can simply set GIT's ssh path c:\Program Files\Git\usr\bin\ssh.exe in the remote.SSH.path setting of VS Code Preferences:
Then it just worked like a charm.
Just for clarity my VS Code version is: 1.40.0-insider (system setup)
I ran into a similar issue trying to get MS VS Code Studio Remote-SSH working with Putty's Pageant. I had Git for Windows installed and in a Git Bash shell, I could ssh and pick up the Pageant keys and no password was needed.
But VS Code Remote-SSH, while using the Git ssh in C:\Program Files\Git\usr\bin\ssh.exe was using Windows 7 cmd.exe shell which didn't talk to Pageant.
What worked for me on Windows 7, VS Code 1.36.1 with (Remote Development 0.15.0, Remote-SSH 0.44.0) and Git for Windows 2.22:
Start Pageant (C:\Program Files\PuTTY\pageant.exe) and Add key.
Start the ssh agent shim (C:\Program Files\Git\cmd\start-ssh-pageant.cmd). This takes care of the communication between Git ssh, which looks for ssh-agent, and Pageant.
Create the SSH_AUTH_SOCK environment variable
Control Panel / System / Advanced Settings / Environment Variables..
User variables for username / New..:
Variable name: SSH_AUTH_SOCK
Variable value: /tmp/.ssh-pageant-username (e.g. /tmp/.ssh-pageant-bill) (Environment Variable assignment screenshot)
Test ssh:
Open a command prompt: Enter set to view the list of Environment Variables. Is the SSH_AUTH_SOCK variable set correctly to something like /tmp/.ssh-pageant-bill?
Try ssh to your host using Git's ssh.exe: c:\Program Files\Git\usr\bin\ssh.exe user#host If this works, then VS Code Remote-SSH should work.
Finally, I added Pageant and start-ssh-pageant.cmd to my Windows 7 Startup so this persists across reboots.
Hope that helps.
Jerry.
I had a similar problem trying to get VS Code Remote use Putty Pageant.
1. Create .bat file somewhere with the following content:
echo OpenSSH
"C:\YOUR_PATH_HERE\PLINK.EXE" -ssh %*
2. Open VS Code settings, type remote ssh path in search and find Remote.SSH: Path settings
3. Past here path to your .bat file
4. Now VS Code Remote will use Pageant correctly.

'ls' is not recognized as an internal or external command, operable program or batch file

'ls' is not recognized as an internal or external command, operable program or batch file.
I get this error when I try to glance at the files of my folder.
cmd opened regularly(not as an admin).
I've recently downloaded anaconda for python.During the installation process, there was a time when I allowed to add a PATH which was not recommended.
'ls' used to work well be
Here are the paths
I'm fairly certain that the ls command is for Linux, not Windows (I'm assuming you're using Windows as you referred to cmd, which is the command line for the Windows OS).
You should use dir instead, which is the Windows equivalent of ls.
Edit (since this post seems to be getting so many views :) ):
You can't use ls on cmd as it's not shipped with Windows, but you can use it on other terminal programs (such as GitBash). Note, ls might work on some FTP servers if the servers are linux based and the FTP is being used from cmd.
dir on Windows is similar to ls. To find out the various options available, just do dir/?.
If you really want to use ls, you could install 3rd party tools to allow you to run unix commands on Windows. Such a program is Microsoft Windows Subsystem for Linux (link to docs).
We can use ls and many other Linux commands in Windows cmd. Just follow these steps.
Steps:
1) Install Git in your computer - https://git-scm.com/downloads.
2) After installing Git, go to the folder in which Git is installed.
Mostly it will be in C drive and then Program Files Folder.
3) In Program Files folder, you will find the folder named Git, find the bin folder
which is inside usr folder in the Git folder.
In my case, the location for bin folder was - C:\Program Files\Git\usr\bin
4) Add this location (C:\Program Files\Git\usr\bin) in path variable, in system
environment variables.
5) You are done. Restart cmd and try to run ls and other Linux commands.
you can use dir instead of ls in cmd
If you want to use Unix shell commands on Windows, you can use Windows Powershell, which includes both Windows and Unix commands as aliases. You can find more info on it in the documentation.
PowerShell supports aliases to refer to commands by alternate names.
Aliasing allows users with experience in other shells to use common
command names that they already know for similar operations in
PowerShell.
The PowerShell equivalents may not produce identical results. However,
the results are close enough that users can do work without knowing
the PowerShell command name.
when you use windows as operating system you should write dir
and you will find all folders including empty folders and their data bytes storage
and you can use git ls-files to show all folders but not including hidden folders
The reason you cannot run the ls command is because it does not exist on windows. The windows equivalent is the dir command, however it does not work the same way. The solution, Winls. It is
The ls command, written for windows.
According the the Winls github.
Had this error because i was using command prompt to access my files.
how did i solve it...
i opened my folder with vscode, and used bash from the terminal...the "ls" command worked as it should from bash.

How to get Visual Studio to recognise a network drive mapping

I have the following Post-Build event defined in my project:
if "$(ConfigurationName)"=="Release" ("$(ProjectDir)PostBuildRelease.bat" "$(TargetDir)")
So when I build the project in release mode, the following .bat file is executed:
PostBuildRelease.bat
CMD
SET parameter=%1
CD %1
ECHO "Copying temporary file..."
COPY FileDeleter.exe temp.exe
ECHO "Merging dependancies..."
"..\..\ILMerge.exe" /out:"FileDeleter.exe" /targetPlatform:"v4" "temp.exe" "Microsoft.WindowsAPICodePack.dll" "Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" "Microsoft.WindowsAPICodePack.Sensors.dll" "Microsoft.WindowsAPICodePack.Shell.dll" "Microsoft.WindowsAPICodePack.ShellExtensions.dll"
ECHO "Removing temporary file..."
DEL temp.exe
All it does is copy the assembly to a temporary location, merge the required dependancies into a final executable FileDeleter.exe, and then removes the temporary file.
This worked fine when the project was saved to a local drive, but after moving the project to a network drive, I get these errors when building in Release mode:
'\\file\IT\Internal Apps\AppDev\Applications\WpfFileDeleter\WpfFileDeleter\bin\Release\'
CMD does not support UNC paths as current directories.
C:\Windows>"Copying temporary file..."
The system cannot find the file specified.
"Merging dependancies..."
'"..\..\ILMerge.exe"' is not recognized as an internal or external command,
operable program or batch file.
"Removing temporary file..."
Could Not Find C:\Windows\temp.exe
CMD complains about not supporting UNC paths.
However, I know that the drive in question (\\File) is actually mapped to the Y:\ drive - so I can navigate to the directory in CMD by targeting Y: instead of \\file\.
The question is - how can I get Visual Studio to recognise this drive mapping by default, after all my projects have been moved to this network drive?
I've learned that batch dosnt like going over a network dir unless you add it as a drive with pushhd. This has worked for me like a charm when working over the network.
PUSHD is an internal command. If Command Extensions are disabled the PUSHD command will not accept a network (UNC) path."
Source:
http://ss64.com/nt/pushd.html
I was able to find a solution to this using this answer:
Remove project from Visual Studio solution
Right-click the solution and "Add existing project"
Navigate to the .csproj file, making sure to navigate to it using the mapped drive, (i.e. Y:\folder\test instead of \\file\folder\test)
Now once the project is added, the TargetDir variable will be set using the mapped drive instead of \\file, meaning that no changes are necessary to the post-build event or the batch file.
Another option, as I am using Team Foundation Services in VS, is to remove all existing local git repositories from Team Explorer -> Manage Connection -> Local Git Repositories and then re-adding the same locations, but again when navigating to the folder, use Y:\ instead of \\file.
Now any project I open from these repositories automatically has their TargetDir paths set using the mapped drive.
The other answer here also worked, but requires changing the post-build event to use the hard-coded mapped path as well as changing the batch file to use PUSHD instead of CD.

Where and how to create symlink from public/storage to storage/app/public in laravel 5.2 on homestead on window

how to create symlink from public/storage to storage/app/public in homestead on window.
and how do i access my files from browser, so if i visit that image url via browser then it will show that particular image.
actually i'm building an api which accessible from any domain , so i have to return the url of that particular image which is uploaded. so it will be shown of front end.
i'm also saving path to database which is - storage/app/public/image.png . what should i do now..
I'm new to file system so may be i need steps by step instruction.
i will be so thankful for the help
I had the same problem creating a symbolic link from the "public" folder to a location on the "storage" directory.
I tried to use "mklink /j" as well to create the symlink. However, when I "vagrant ssh" to the virtualbox, I found that it did not actually create the link correctly. Attempting to "cd" to the created link would cause an error. Also it wasn't shown as a symlink in the usual linux notation.
To allow the symlink to be created in the virtualBox:
Open "Local Group Policy Editor".
Go to: Computer Configuration | Windows Settings | Security Settings | Local -Policies | User Rights Assignment
Find the "Create symbolic links" policy and add your logged in user to it.
Restart your host windows machine. ssh to your virtualbox. You may need to run "vagrant up" as an Administrator by opening your CMD using "Run as administrator" option.
Go to your "public" folder, and create your symbolic link using the linux "ln -s" command. It should work now.
I was using Windows 10, but the above should be the same for Windows 7.
The "Create symbolic links" policy may be located somewhere slightly different for earlier versions of Windows.
Credit should go to this blog: Symlink support in Windows and Virtualbox
I tried this and it works. Running homestead on VirtualBox on Windows 10:
Open cmd as administrator
Click Start->Run
Type 'cmd', and press ctrl-shift-enter
Select 'yes' from the pop-up window
Type the following command:mklink /D c:\<project_directory>\public\storage "/home/vagrant/<project_directory>/storage/app"
Then the storage/app will be accessible from public/storage in Homestead VM. Note that this is assuming C:\ is shared as /home/vagrant in Homestead VM.
On a MacOS you need to go to your Homestead folder and:
run: vagrant ssh
navigate to your project root folder
run: php artisan storage:link
And you are done.
If you do this without ssh to vagrant then it will not work.

Execute windows batch command from Jenkins fails but runs fine in cmd.exe

I am trying to run this command in jenkins after a MSbuild
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Y: is a mapped network drive. This runs fine in cmd.exe but when trying to run it in Jenkins, I am getting the error Invalid drive specification.
Here is the output from jenkins:
Time Elapsed 00:00:04.03
[trunk] $ cmd /c call C:\Windows\TEMP\hudson3389873107474371072.bat
C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Invalid drive specification
0 File(s) copied
C:\Program Files (x86)\Jenkins\workspace\trunk>exit 4
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Any help would be appreciated.
I too had a similar issue once. Try granting the Jenkins service "Logon as This account" right under services.msc and make sure the account you type there is the same as the one you use for running cmd.exe.
These commands based on Java JAR files worked for me:
cmd
net use x: \\
xcopy "dist\" x:\ /Y
And that's it! I spent lot of time figure out this issue and nothing worked until I wrote CMD and NET USE!
Neither I didn't need to change permission on jenkins service nor use runas command.
But I must mention that everyone had read and write access to the network drive.
I had the same issue with my Windows Task running a batch file (I know it is not exactly same) where I tried to copy file to network location i.e. shared drive. I used the UNC path and mapped drive as well but the error was same. For me it was error number 4 - MS DOS error code.
The solution was to use net use command! Hope that it helps.
Easy fix for most things.
Make a batch command with what your trying to run, filename.bat with the command prompt text inside.
Make a normal windows shortcut for the batch command, edit the shortcuts advanced properties and check the "Run as admin" (tricky tricky).
Now run the filename.lnk shortcut from jenkins command line call, this will get you around all the jazz.
:)
The solution of adarshr (i.e., modifying the log on credentials of the service) has worked for me for a part of the problem: in my case, this allowed me to successfully check out a mercurial repository (using ssh protocol), which I could not do when using 'Local System account'.
However, I still have different behavior between running a command-line script or running the same script from a jenkins 'execute shell' script in the build section. In my case, I compile a Python extension. In Jenkins, I cannot import the extension (I don't see any error, but the execution simply stops, so I suspect it crashes).
If I uninstall the service and run the slave agent as a Java Web Start, I do get the same behavoir. It is a temporary fix for me, but it means that when I reboot the windows build machine, I have to manually re-start the Java Web Start application.
So -at least in my case- it is clear that this is a credential problem.
Credentials usage documentation: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
I've solved my issue with the CIFS plugin.
Faced similar issue and found two ways to solve.
Type 1:
Tell Jenkins about mapped drive.
1.Goto -> Manage Jenkins -> Script Console (Groovy Script).
2.Run below command
def mapdrive = "net use Y: \\\\copy_nework_address"
mapdrive.execute();
println "net use".execute().getText()
Type:2
1.Goto -> cmd -> run "net use" to know network address
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Copy_Network_Address\Extraction_Zone\Jenkins\" /E
Conclusion:- I prefer 2nd types as after every restart i should run Groovy Script.

Resources