18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

pass value from command line prompt or batch file to sahi script

vikkyjainvikkyjain Members
edited November -1 in Sahi - Open Source
Hi,

I want to pass a value form CMD to my script . Hows this possibe,

Desc - Actually i m having a batch file by which i m running my script. SO before running script , i want to create a folder , and folder name i want to pass in in script , hows this possible ??

Comments

  • Hello Vikkyjain,

    This might be possible with a workaround.
    From the batch file, you can try sending the name of the folder to a txt file and use the _readFile() API to fetch the folder name from this file.

    Will this solve your problem?

    Regards,
    dkulkarni
  • Hi dkulkarni,

    By this way it will solve the problem, But in my automation script, i m already using lot of files , which i m reading in my script. This way will create another file,
    SO Is it not possible directly without creating other file.

    My batch file is like this

    java -cp C:\sahi\lib\ant-sahi.jar net.sf.sahi.test.TestRunner "C:\sahi\userdata\scripts\debugger.sah" "C:\Program Files\Mozilla Firefox\firefox.exe" default localhost 9999 1 firefox.exe

    Can you please see whether -extraInfo is useful ???
    Or you have any other way ??
  • narayannarayan Administrators
    You can create the folder from inside the script also.
    Just do

    var $dir = new java.io.File("C:\\path\to\\folder");
    $dir.mkdirs();

    If you really want to use a batch file output, redirect the output to a file, and then read it using
    _readFile("filepath") API in Sahi script.

    Regards,
    Narayan
  • Hi Narayan,

    Basically in my batch file I am creating a folder with name of current date and time.
    and that name i stored in a variable. Now that folder name will contain my resultant files of scripts.
    For that i need this name to be passed into my script.

    Please find below my batch file

    @echo off
    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
    for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
    for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
    for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
    set TODAY=%day%%month%%year%_%hour%%minutes%%ampm%
    rem echo %TODAY%
    set A = result
    set B = /
    echo %TODAY%


    mkdir result\%TODAY%

    java -cp C:\sahi\lib\ant-sahi.jar net.sf.sahi.test.TestRunner "C:\sahi\userdata\scripts\debugger.sah" "C:\Program Files\Mozilla Firefox\firefox.exe" http://www.google.com default localhost 9999 1 firefox.exe


    So i need this folder name inside my script. this is my basically problem ..

    Please help me on this in another way else way dKulkarni suggest will work, but i dont want to create some more files in my project.

    Thanks in advance
Sign In or Register to comment.