Problem while using cd command in cygwin based windows batch script - batch-file

I am facing a problem in windows batch script. I have installed cygwin in my system. So i am using bash commands inside my batch script for efficiency. Consider the below command
cp -rf D:/Ashok E:/Data
E:
cd E:/Data
cd E:/Data
Output is
c:>sample.bat
c:>cp -rf D:/Ashok E:/Data
c:>E:
E:>cd E:/Data
E:/Data>cd E:/Data
The system cannot find the specified path
While in the same folder (E:/data), i am trying to do the cd, that time i am getting error message. Because it treated that entire "E:/Data" as a folder name. How to get rid of this problem. What we can do to solve this problem.

Have you tried using the cygdrive prefix?
cd /cygdrive/e/Data

Using the proper back slash in the cd command will solve the problem. But cp command is supporting both the slashes.
c:>sample.bat
c:>cp -rf D:/Ashok E:/Data
c:>E:
E:>cd E:\Data
E:/Data>cd E:\Data

Related

cp: target '/path/to/directory' is not a directory

I really confused by target /path/to/directory is not a directory when i want to copying all files in build/* to the direction in by this rule in gitlab-ci.yml file:
script:
- cp -rf build/* /path/to/directory
I've also check this command by removing/adding / at end and start of the destination but won't help.
Note: it's OK when i manually run the cp command in server terminal and have no problem with it.This command was successful when i run it manually through terminal in ubuntu server.
So what's the problem here?
it's OK when i manually run the cp command in server terminal and have no problem with it.
That is probably because the target folder exists in the server itself, while it might not exist in the context of the GitLab runner.
You should either:
create the target folder:
mkdir -p /path/to/directory
or mount the server target folder as a data volume:
volumes = ["/path/to/bind/from/host:/path/to/bind/in/container:rw"]
I experienced a similar error because one of my files had a space in its name and so the path it was looking for was only reading the string after the space.

MinGW32-make path variable issue

I am trying to build a C project on Win10 and i am using MinGW32-make. Prior to build the build directories should be created, and this is where build breaks with following output:
mkdir build\f2803x
process_begin: CreateProcess(NULL, mkdir build\f2803x, ...) failed.
make (e=2): The system cannot find the file specified.
Makefile:64: recipe for target 'build\f2803x' failed
mingw32-make: *** [build\f2803x] Error 2
I've tried running the mkdir command from the command line and it runs successfuly, however when i try running mingw32-make it fails. I've been searcing the web and one answer to the similar question pointed out that PATH in for the Mingw32-make and PATH for the windows may not be the same, so i added echo path to the makefile and compared the output to echo %PATH% from the cmd. It appears that they are not the same. Mingw32-make has
/mingw64/bin:/usr/bin:/c/Users/user123/bin that is not stated anywhere in any of the windows environment variables. I've also searched the registry as a last resort, however this is not in registry either. Where can these additional paths come from, and is it even the issue of the path?
mkdir is not a program, it's a built-in command interpreted by cmd.exe.
You want:
cmd.exe /c mkdir build\f2803x
I've been chasing a similar problem. For me the error was due to a missing command (I didn't have a date command available). Check your path and make sure that your make can find the mkdir command. Also, make sure you are executing a *nix style mkdir, not the dos/windows mkdir.

'tar' is not recognized as an internal or external command

I am trying to extract a zip file in Windows 10 using a batch script.
It a simple command:
tar zxf "logstash-5.4.0.tar.gz"
ECHO "installed"
But I am getting following error:
'tar' is not recognized as an internal or external command
I have seen that I have to install the tar but how can I do that?
How can I do this?
EDIT Tar is pre installed in windows or we have to externally add it? Still how can i extract without using third party tool.
You can download Tartool Application in your desktop and paste it into
C:\Windows\system32\
For eg:-(C:\Windows\system32\tartool.exe)
By doing this it work as internal command when you want to extract your file you can simply use
C:>TarTool.exe D:\sample.tar.gz ./
For more commands you can read documention part of that Tool
Starting windows 10 build 17063, TAR is an inbuilt tool and no need to install it separately. MSDN link
For example, to uninstall a file named XYZ.zip you can execute the following in Command Prompt.
tar -xvf XYZ.zip

wget not recognized as internal or external command

I am working on a program to auto update my game as I make new developments and add new patches. When I go to run the patch update it doesn't recognize wget as a internal or external command.
Game:
:Checkforupdates
cls
cd C:\AirlineSim\
echo Checking for Updates
wget "http://interversesoftware.weebly.com/uploads/4/8/5/8/48585729/aspatcher.bat"
if /i not exist "ASpatcher.bat" (echo Could not retrieve update file.) && pause
if exist "ASpatcher.bat" call "ASpatcher.bat"
if exist "ASpatcher.bat" del "ASpatcher.bat"
goto menu
More code above in the updater
Updater:
cd C:\Airlinesim
echo Updating...
echo.
if /i exist Airline_Simulator.bat" del Airline_Simulator.bat
wget "http://interversesoftware.weebly.com/uploads/4/8/5/8/48585729/airline_simulator.bat")
set version=2.0
wget is a third-party program that doesn't come bundled with Windows, so you need to explicitly install it in order to use it.
You can find (one of) the Windows versions here: http://gnuwin32.sourceforge.net/packages/wget.htm
You will need to add the path of the wget.exe file to your PATH environment variable in order to call the executable as in the batch file above without explicitly specifying the path.
For Windows 10: A good link is available here: https://builtvisible.com/download-your-website-with-wget/
I followed this tutorial-> (https://builtvisible.com/download-your-website-with-wget/) and it worked for me. Still, I will give an overview of that,
credit: Richard Baxter
for 64bit version download wget from here
move your wget.exe to the Windows directory, which is generally c:\Windows\System32.if you don't know then you can find that either using the $PATH command or by opening your cmd as an administrator and in which path it will open that will be your Windows directory. like this one ->
2.1. Check that you have copied that in a proper place or not, to do that restart your cmd/terminal then type wget -h. if it gives some output related to some commands and their utilities(basically what a help command does) then you are good to gođź‘Ť.
If you pass the above check, then go to your c:/ directory using cd .., then make a directory called wgetdown using md wgetdown. Now you are all set. use get how ever you want.
What this simply means is, wget isn’t installed in your windows machine or it is, but hasn’t been added to Windows environmental path.
If you don’t have wget installed, download it from here (32-bit) and here (64-bit).
Extract the files to a folder say C:\wget and then add the folder to Windows environmental path.
Go to C:\Program Files (x86)\GnuWin32\bin folder and check the .exe file name.
For me it was sid.exe so I'm using sid instead of Wget command
download wget.exe here after downloading, go to command prompt by typing 'cmd' in the search menu, open the cmd type 'path' then enter in the command prompt, you're going to move the downloaded wget.exe to C:\Windows\System32 folder. if its successful, close and open the command prompt and type 'wget -h' then enter you should see different available commands. You can now use 'md wgetdown' to create directory for your downloads
first you have to install wget
pip install wget
than in Jupiter notebook locally on Windows 10
!python -m wget
example
!python -m wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1InzR1qylS3Air4IvpS9CoamqJ0r9bqQg' -O inception.py
You simply need to install wget from https://anaconda.org/menpo/wget here. I found my solution by installing it.
I had a similar issue, and I resolved it by using Windows PowerShell instead of Command Prompt
The answers about it not being available by default are absolutely correct. A few other notes related to installing wget - if you use a package manager, they may have it for you to install with.. e.g.:
$ choco install wget
$ composer require fawno/wget

Unzip tar.gz in Windows

I would like to unzip Filename.tar.gz to Filename using single command in windows batch script
All the files inside zip should go inside the Filename Folder
I am trying to do in windows . I am not getting correct output.
Can anyone suggest an idea
Windows Command line now supports tar from Windows 10 insider build 17063. You may try run the below command in cmd or PowerShell to see if it works:
tar xzvf your-file-name.tar.gz
7 zip can do that: http://www.7-zip.org/
It has a documented command line. I use it every day via scripts.
Plus: it is free and has 32 and 64 bit versions.
Windows 10 command line supports tar command
Write the tar command as general to the Linux terminal.
tar -zxvf tar-filename.tar.gz --directory destination-folder
Another option is the Arc program:
arc unarchive test.tar.gz
https://github.com/mholt/archiver
in windows compand promt use quotation marks ("") when specifying the path. It will work properly
Exaple : tar -xvzf "C:/PATH/TO/FILE/FILE-NAME.tar.gz" -C "C:/PATH/TO/FOLDER/EXTRACTION"
tar -xvzf "C:/PATH/TO/FILE/FILE-NAME.tar.gz"

Resources