Running bat file in linux

How to run bat file in linux

Solution: Because of the fact that you .ahk script requires the actual autohotkey program on windows to run (it’s the interpreter between raw text and binary commands to windows), what you’re likely running into is that the bat file is trying to just «run» your .ahk script, but can’t run a raw text file like a program. The CMD language does not have a lot of programming constructs and rarely used to do anything complicated, they are very windows specific and mainly used to start up other programs on windows.

How to run a bat file in windows from linux systm

Because of the fact that you .ahk script requires the actual autohotkey program on windows to run (it’s the interpreter between raw text and binary commands to windows), what you’re likely running into is that the bat file is trying to just «run» your .ahk script, but can’t run a raw text file like a program. What you may be able to do to fix this is compiling your .ahk script, making it an executable. Then, you could call the executable directly, just like you would any other .exe on the computer. (you might also want to try starting any other .exe this way like notepad to make sure your method of running the program is correct)

Another solution would be, as @Matthew Strawbridge suggested, to have a script running quietly in the background of the computer, periodically checking the contents of a file that the .bat can write to. This has the added bonus of you being able to customize what the script does by what is written in the check up file.

How do i make my .bat file run linux command to, Below is my current .bat content. i run it on window cmd. it will connect to remote linux server and prompt me password. but after i put the password and login as remotehost, linux server wont run my ls command. please help. @echo off ssh remotehost@10.1.1.10 ls

How do i make my .bat file run linux command to remote linux

You really should do man ssh as this is explained there (and you could also make an internet search to get an answer).

But, to answer your question anyway: you should put all commands you want to run on the remote machine on the same line with the actual ssh command, for example to run directory listing and grep all files containing «foo», do: ssh @ ‘ls|grep foo’ .

I hinted that it is possible to have the code in a batch file in my comment to @Sami Laine. This is what it would look like:

@echo off setlocal :: Run the end of this file in remote computer more +8 %0 | plink user@remote.compu.ter "tr -d '\r'| bash" endlocal exit /b 0 :: remote bash stuff to be bootstrapped pwd ls -h 

I’m using plink, because that what I have installed but it should work with most flavors of ssh too. Works also with ksh and zsh. Probably also with tcsh csh etc. This can sometimes be useful. Same technique can be used for a lot of things. Be careful with the +8 offset value it has to be on the right line.

Читайте также:  Настроить горячие клавиши линукс

Batch command in Linux with Examples, Executing some commands using batch. See the average load is lower than 1.5 that’s why the job queue is empty and command executed instantly. Use ctrl +d when done giving commands to batch. Find the value of XXXX.. (N times) % M where N is large Article Contributed By : VivekAgrawal3 …

Run windows nt’s cmd or bat files on linux

You don’t want to run .bat files on linux, if you really want to do that, you can use WINE on linux. The CMD language does not have a lot of programming constructs and rarely used to do anything complicated, they are very windows specific and mainly used to start up other programs on windows.

There is a relatively simple way to wrap bash scripts in .bat though.

@setlocal @cd C:\cygwin\bin @start bash --login -i /home/your_id/yourscript @endlocal 

Batch — Unix, Linux Command, batch [ -V] [ -q queue] [ -f file] [ -mv] [ TIME] DESCRIPTION at and batch read commands from standard input or a specified file which are to be executed at a later time . At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a specific time of day.

Executing .bat file

You can run DOS batch file through wineconsole :

$ cat ~/.wine/drive_c/file.bat @echo off echo Working pause $ wineconsole 'C:\file.bat' 

You get a new windows similar to this

Also, you can enter an interactive DOS prompt with

You have to run it through cmd eg.: wine cmd /c setup.bat

Firstly, Wine won’t touch batch files.

Why do you have to do it in a terminal? Just open the directory with naultilus, right click the .7z files and extract. But if you want to do it the hard way, the appriximate conversion of that script is:

#!/bin/bash 7za x RipForGames.7z # might want e instead of x #rm RipForGames.7z # commented out in case you want to keep them. 

A protip for next time: Try not to announce you’re downloading pirated material, in a public forum. It might come back to bite you in the arse one day.

How to run a bat file in windows from linux systm, Another solution would be, as @Matthew Strawbridge suggested, to have a script running quietly in the background of the computer, periodically checking the contents of a file that the .bat can write to. This has the added bonus of you being able to customize what the script does by what is written in the …

Источник

Can I run Windows .bat files in Ubuntu?

I want to run a .bat file in ubuntu, but it just opens the text editor. Here’s the code of the .bat file(you can play it):

@echo off set /a guessnum=0 set /a answer=%RANDOM% echo Welcome to the Guessing Game! echo. echo Try and Guess my Number! echo. echo. goto guess :guess set /p guess= set /a guessnum=%guessnum% +1 if %guess% GTR %answer% ECHO Lower! if %guess% LSS %answer% ECHO Higher! if %guess% EQU %answer% GOTO EQUAL goto goto guess :equal echo Congratulations, You guessed right. echo. echo It took you %guessnum% guesses. echo. pause 

The file is seen as being text; hence opening in the text editor. Files are marked as executable via chmod (or GUI tools) which you didn’t do, but the file must have an interpreter installed that knows how to execute it (usually the type of file can be determined, but the shebang on first line is always a safety item to ensure it’s interpreted correctly — your file has none). You’ll need to add software that knows how to interpret it, as it’s not BASH script, not perl, not python, not CSH etc.

Читайте также:  Установка cmake astra linux

This code is erroneous, so there is no output from this batch file. The statement goto top can’t be executed because there is no label named :top in this batch file. Debugging batch files is off topic at Ask Ubuntu. Try asking for help at a Windows site or Stack Overflow.

2 Answers 2

By the looks of it, most of it (the parts using the “echo” command) should work, but not the batch-specific parts (e.g. “goto”). But you should be able to convert it to a shell script and then it might work, or you may be able to emulate it within Ubuntu.

Edit: I’ve converted it, it appears to be incomplete. It appears to have converted the «if» parts, but not anything else. Let me know if it works (I highly doubt it), I’ll also try it personally. I hope it helps. (Moderators, please update this answer with a fully converted script if possible.)

export -a guessnum=0 export -a answer=$ echo Welcome to the Guessing Game! echo "" echo Try and Guess my Number! echo "" echo "" export -p guess= export -a guessnum=$ +1 if $ echo Lower! if $ echo Higher! if $ echo EQUAL goto top :equal echo Congratulations, You guessed right. echo "" echo It took you $ guesses. echo "" pause 

Источник

Running Windows Batch Files on Linux

I have noticed that many people on the Internet ask about running Windows batch files on Linux. Unfortunately, many of the answers such people receive state that batch scripts cannot run on Linux. However, Linux users can indeed run batch files. Also, Windows batch files can be run on Windows like a native shell script.

First, the Linux system must have Wine installed. On most Linux systems, this requires the user to install the «wine» package. On some Debian-based systems, users may have conflicts with the «nvidia-libopencl1-331-updates» package. This can be fixed by installing «ocl-icd-opencl-dev» and its dependencies. The package manager should remove «nvidia-libopencl1-331-updates», if not, then the user must do so. If for some reason, Wine is not found in the repos, then either add this PPA (ppa:ubuntu-wine/ppa) or go to https://www.winehq.org/ and download the needed package.

Once Wine is installed, open a terminal and run «wineconsole cmd». This will open a separate Windows-Console window. From here, users can run various Windows terminal commands. Batch files can be run by typing «start FILENAME.bat».

linux-starting-wineconsole.png

wine-console.png

Alternately, type «wine cmd» to run the Windows-Console in the Linux terminal.

cmd-in-terminal.png

When in the native Linux shell, the batch files can be executed by typing «wine cmd.exe /c FILENAME.bat» or any of the following ways.
wine cmd < FILENAME.bat
wine cmd.exe < FILENAME.bat
wine start FILENAME.bat
wine cmd /c FILENAME.bat

In the user’s bashrc file (~/.bashrc), it may help to add the following lines for Linux shell scripting purposes.

export WINEPREFIX=$HOME/.wine/ export WINEHOME=$HOME/.wine/ # for 32-bit export WINEARCH=win32 # for 64-bit export WINEARCH=win64

At this point, many Linux users may find it difficult to need to open a terminal and run that command just to run a batch file. Thankfully, there are two ways to fix that problem.

Читайте также:  Astra linux отпечаток пальца

The quickest fix is to add the line seen below to the alias file (~/.bash_aliases). Next, logout and log back in so that the alias file will re-initialize. Then, users can type «winbatch FILENAME.bat» to execute a batch file in a terminal.

The second alternative is to make batch files execute as if they were a native shell script. To do so, download Winescript at http://dcjtech.info/wp-content/uploads/2015/02/winescript-v2015.02.08.zip. Next, uncompress the file and be sure that the file is named «winescript». Then, with Root privileges, move the script to /usr/share/bin/ or /usr/bin/ by typing «mv ./winescript /usr/share/bin/winescript» in a terminal. Finally, make the file executable by running «chmod +x /usr/share/bin/winescript» with Root privileges.

If Winescript and Wine have been installed successfully, then the user must make two changes to batch files to make them act like native scripts. First, make «#!/usr/bin/env winescript» the first line (hashpling) in the batch file. Lastly, make the batch file executable by running «chmod +x ./FILENAME.bat». Now, the user can execute this Windows batch file natively on GNU/Linux.

winescript.png

Now that batch files can be used on Linux, it may help to know some general facts. «*.bat» is the extension that was first used in DOS. Later, Windows NT and OS/2 added «*.cmd». Some shells (like 4OS2) supported the «*.btm» extension.

Источник

How do I create a batch file and run it? [duplicate]

Your question is more likely to receive useful answers if it contains some specifics. Such as what type of data is to be processed, including realistic examples of input and output.

@SergiyKolodyazhnyy The duplicate nominee is closed as too broad. As such the close vote on this one should be «too broad» as well. That said it seems like a reasonable question to me as I was once in the dark myself 🙂

@WinEunuuchs2Unix It is closed but does have an accepted answer, which will give OP what they want, or at least a starting point.

@EliahKagan If a mod agrees perhaps he can reopen that one and then merge the answers from here to there?

@WinEunuuchs2Unix That question, which this received close votes to be duped to, was actually reopened a few hours ago, then closed again as duplicate of that highly voted question. Both of them are listed as «originals» in the duplicate banner here (i.e., this question is duped to both of them). So if answers are to be merged, they’d probably be put there. Do you think that would be useful?

3 Answers 3

To create one use the .sh extension but it doesn’t really matter but it helps future users to quickly determine which file type it is. The bat name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de and it would still run in bash file but I believe it’s a good practice to name them with the .sh file extension.

For the editor, part uses any that is best for you between nano vim gedit emacs , but I believe gedit would be nice to start with.

Источник

Оцените статью
Adblock
detector