Category Archives: batch-file

How to Configure Apache Tomcat ports batch file?

I want to configure apache tomcat (any version) in a batch file. I am doing a project and it's necessary to do this. If it's manually, changing the port works, but automatically, by batch script, doesn't work... I tried to put this:

echo A configurar o tomcat6...  
setx CATALINA_HOME "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53"

COPY tomcat6-shutdown.bat "C:\Program Files\Apache Software Foundation\tomcat6-shutdown.bat"
COPY tomcat6-start.bat "C:\Program Files\Apache Software Foundation\tomcat6-start.bat"

RD /S /Q "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\work"
RD /S /Q "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\webapps\docs"                    
RD /S /Q "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\webapps\manager" 
RD /S /Q "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\webapps\ROOT" 

cd "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\temp"
    del safeToDelete.tmp

cd "C:\Program Files\Apache Software Foundation"
mkdir Tomcat6_instance
Xcopy /E /I "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\conf" "C:\Program Files\Apache Software Foundation\Tomcat6_instance\conf"
Xcopy /E /I "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\temp" "C:\Program Files\Apache Software Foundation\Tomcat6_instance\temp"
Xcopy /E /I "C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.53\webapps" "C:\Program Files\Apache Software Foundation\Tomcat6_instance\webapps"

cd "C:\Program Files\Apache Software Foundation\Tomcat6_instance\webapps"
mkdir test

cd test
(
echo Hello tomcat 6 
) > index.html

cd "C:\Program Files\Apache Software Foundation\Tomcat6_instance\conf"
powershell -Command "(gc server.xml) -replace '8005', '8006' | Out-File server.xml"
powershell -Command "(gc server.xml) -replace '8080', '8082' | Out-File server.xml"
powershell -Command "(gc server.xml) -replace '8009', '8010' | Out-File server.xml"

But this code doesn't work at all. It replaces the ports and send to the server.xml, we also create the envirovment variables with setx CATALINA_HOME and when I try to start the server, the server doesn't connect, and even does not create a service. Anyway, I want some help on this, because changing the port is important and in this project I cannot do it with graphical installation. Are any way of create a batch script to do that or the only way is by graphical installation? In my opinion, this code should have worked, but when I start startup.bat from the folder /bin inside tomcat folder doesn't start after changing the port, but if if the port is 8080 it works.

Apache common daemon procrun with batch file

i wrote a simple batch file which reads the configuration from a external file. the script looks like this:

@echo off


for /f "delims=" %%x in (test-config.txt) do (
    set "%%x" 
)

prunsrv.exe //IS//%SERVICE_NAME%

and my configuration like this:

SERVICE_NAME=TestService
PR_DESCRIPTION=test description

PR_CLASSPATH=TestService.jar

PR_STARTMODE=Java
PR_STARTCLASS=package.Starter

PR_JVM=auto
PR_STARTUP=auto

for some reason, the configuration are not applied at all while installing the service. this can be seen at the description for example, as it does not get set. does anyone know why the configuration is not applied?

How to launch gui app with PHP and bring it to front on Windows?

I am on Windows 10. With Wamp installed that comes with Apache 2.4.18 and PHP 5.6.19.

After going to services.msc->right click on wampapache entry and select properties-> go to the Log On tab and check "Allow Service to interact with Desktop", and launching Apache by going directly to C:\wamp\bin\apache\apache2.4.18\bin and double click httpd.exe (for some reason launching Apache through wamp doesn't work)

I am able to successfully launch notepad.exe with the below php code invoked in the chrome browser by going to the address http://localhost/test.php

//test.php
<?php
   exec('notepad');
?>

However, the problem is notepad is not automatically shown on top of the browser. After a bit of googling I found that nircmd has a command to move the window to the front.

I attempted

<?php
   exec('notepad');
   exec('nircmd win activate title "Untitled - Notepad"');
?>

Which work perfectly if ran on normal command prompt but for some reason the second exec never gets executed. The next attempt is

<?php
   exec('notepad & nircmd win activate title "Untitled - Notepad"');
?>

Still no effect, so I tried

<?php
   exec('start "" notepad & start "" nircmd win activate title "Untitled - Notepad"');
?>

but this only works 1 out of 5 times, so I suspect there might be racing condition because notepad has to be opened before nircmd is executed, so the last attempt is

<?php
   exec('start "" notepad & sleep 1 & start "" nircmd win activate title "Untitled - Notepad"');
?>

But this still only works 1 out of 5 times. What is the right approach to launch notepad.exe and bring it to the front?

How can I run the ij tool from java code

I try to run the *.bat files of derby, but I can't do this.

I want to run the "startNetworkServer.bat" and "ij.bat" using by java code. I try to write some simple code but it not working.

package dbconnect;

import java.io.IOException;

public class RunDerbyTools {

    public static void main(String[] args) {

        String pathIj, pathStartNetwork, pathStopNetwork;

        pathIj = "C:/MyWorkSpace/MyDBProject/db/bin/ij.bat"; // running ij tool

        // running network
        pathStartNetwork = "C:/MyWorkSpace/MyDBProject/db/bin/startNetworkServer.bat";

        // stop network
        pathStopNetwork = "C:/MyWorkSpace/MyDBProject/db/bin/stopNetworkServer.bat";

        try {
            Process pStartNetwork = Runtime.getRuntime().exec(pathStartNetwork);

        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            Process pPathIj = Runtime.getRuntime().exec(pathStartNetwork);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Need Help! Thank!

How to hide Command Prompt window after starting apache and mysql service?

I have a batch file for running apache and mysql service in one go but this batch open a blank command prompt and does not close it.

@echo off
@start /b "" d:\hlwamp\apache24\bin\httpd.exe 
@start /b "" d:\hlwamp\mysql\bin\mysqld.exe 
exit

How to automatically close the cmd after command execute. Or How do I just run the Batch file without seeing the prompt? The code works and starts both the services but the apache cmd is not closing.

Automatic change root directory of Apache

¡Hola, amigos!

I want to automate the process of setting the Apache's root directory with a batch file (Just because, there's not a good reason but saving like 3 seconds of my life). To do this, I need to replace lines #244 and #245 with %cd%

First, I've created a PATH to the batch file, so in cmd I write "> serveThis" and it runs the .bat file. That works fine.

Now, the tricky part (for me), the Batch file (From this):

@echo off &SETLOCAL

SET "file=C:\xampp\apache\conf\httpd.conf"
SET /a Line#ToSearch=244
SET Replacement = DocumentRoot "%CD%"

(FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
    SET "Line=%%b"
    IF %%a equ %Line#ToSearch% SET "Line=%Replacement%"
    SETLOCAL ENABLEDELAYEDEXPANSION
    ECHO(!Line!
    ENDLOCAL
))>"%file%.new"
TYPE "%file%.new"


SET /a Line#ToSearch=245
SET Replacement = DocumentRoot "%CD%"

(FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
    SET "Line=%%b"
    IF %%a equ %Line#ToSearch% SET "Line=%Replacement%"
    SETLOCAL ENABLEDELAYEDEXPANSION
    ECHO(!Line!
    ENDLOCAL
))>"%file%.new"
TYPE "%file%.new"

tbh I don't completely understand what's happening, but It doesn't work. Any idea?

I've aldo found this, but I didn't understand.

Nginx php files loading slow

EDIT: I have noticed the first time you visit it to goes fast, and it also goes fast if you close the browser tab and re-visit it, but if you simply reload or visit it when you have a tab of it open it goes slow, it is really confusing.

today I come with a problem about PHP CGI, I am brand new to nginx and have just installed it, when I noticed I need to start PHP cgi also with it because with IIS it started it for me. so I start php with batch file below but the problem is... slow php files, they load really slowly even if its just html in them.

@ECHO off
echo Starting PHP, please wait!
C:\nginx\php7\php-cgi.exe -b 127.0.0.1:9054 -c C:\nginx\php7\php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT

Am I doing anything wrong with my batch file or nginx config below? (I have 2 configs) the example.com one is the website with a .php file and the nginx (localhost) just has index.html

localhost loads super fast but example.com one loads really slow because of php.

nginx.conf worker_processes 1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   C:\Users\Administrator\Dropbox\websites\local_website;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            if (!-e $document_root$document_uri){return 404;}
            fastcgi_pass localhost:9054;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

    include vhosts/*.conf;
}

example.com.conf

server {
    listen   ***.***.**.***:80;
    server_name  example.com www.example.com;

    root C:\Users\Administrator\Dropbox\websites\php_website;
    index index.php index.html;

    log_not_found off;
    charset utf-8;

    #access_log  logs/example.com-access.log  main;

    location ~ /\. {allow all;}

    location / {
        rewrite ^/(|/)$ /index.php?url=$1;
        rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
        rewrite ^/(.*)\.htm$ /$1.php;
    }

    location = /favicon.ico {
    }

    location = /robots.txt {
    }

    location ~ \.php$ {
        if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass localhost:9054;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Nginx php files loading slow

EDIT: I have noticed the first time you visit it to goes fast, and it also goes fast if you close the browser tab and re-visit it, but if you simply reload or visit it when you have a tab of it open it goes slow, it is really confusing.

today I come with a problem about PHP CGI, I am brand new to nginx and have just installed it, when I noticed I need to start PHP cgi also with it because with IIS it started it for me. so I start php with batch file below but the problem is... slow php files, they load really slowly even if its just html in them.

@ECHO off
echo Starting PHP, please wait!
C:\nginx\php7\php-cgi.exe -b 127.0.0.1:9054 -c C:\nginx\php7\php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT

Am I doing anything wrong with my batch file or nginx config below? (I have 2 configs) the example.com one is the website with a .php file and the nginx (localhost) just has index.html

localhost loads super fast but example.com one loads really slow because of php.

nginx.conf worker_processes 1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   C:\Users\Administrator\Dropbox\websites\local_website;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            if (!-e $document_root$document_uri){return 404;}
            fastcgi_pass localhost:9054;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

    include vhosts/*.conf;
}

example.com.conf

server {
    listen   ***.***.**.***:80;
    server_name  example.com www.example.com;

    root C:\Users\Administrator\Dropbox\websites\php_website;
    index index.php index.html;

    log_not_found off;
    charset utf-8;

    #access_log  logs/example.com-access.log  main;

    location ~ /\. {allow all;}

    location / {
        rewrite ^/(|/)$ /index.php?url=$1;
        rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
        rewrite ^/(.*)\.htm$ /$1.php;
    }

    location = /favicon.ico {
    }

    location = /robots.txt {
    }

    location ~ \.php$ {
        if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass localhost:9054;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Bash Script not being able to run on X2Go

I've currently saved an .xml file that runs information about the Bible. I've saved the file as testingbible.sh and in the following location:

/home/testteam/SmartBear/SoapUI-5.2.1/bin/testingbible.sh

However when I attempt to run the file by simply double clicking it, nothing appears to happen. I've applied the following to the file:

chmod 755 testingbible.sh and it does nothing.

The file contains the following:

sh -c ./testrunner.sh -s"BibleWebserviceSoap TestSuite" -j - f/home/docs/SoapUI/Reports /home/docs/BibleWebservice-soapui-project.xml

We're trying to automate tests from SoapUI in order to avoid having to open it up to execute tests and simply rely on the bash script to execute the .wsdl script and if any errors arise from the .sh script, they are flagged.

I've replicated the above on my Windows machine, this results in the bat file quickly flashing and then it disappears.

Any help would be greatly appreciated.

How do I tell my browser to save a batch file instead of viewing it? [duplicate]

This question already has an answer here:

I have a simple HTML page with a few links on it. The links point to some batch files on the server. When I click on the links, the batch files will appear in the browser window as plain text, instead of prompting me save them locally.

So next I decided to use the old right-click, "Save target as..." trick. This works in Chrome, but when using IE, the files save with a .HTM extension instead of the .BAT extension that I need.

I don't know if this can be resolved by making changes on my end. The links are super simple. Literally I am typing <a href="files/example.bat>click me</a>. I even removed the "target="_blank" portion, just in case that was messing with it.

I seem to get the same result with any "text-only" file. Any ideas are appreciated.