Clear Values On Bat Or Catch Null Value On If Statement - if-statement

So I'm Trying To Wipe Variables After Use, Easiest Way I Found Was To Declare As It Follow's
:PING_IP
set IP=
set /p IP="Enter IP To Ping(0 Cancel): "
if %IP%==0 (
cls
goto IP_MENU
) else (
ping %IP%
pause
cls
goto IP_MENU
)
But In This Case Bat Will End, Cause There No Action To Capture The NULL Value Var If Not Use, Unsure How To Proceed

Just Found Out I Can Use "||" To Assign A Value If User Does Not Responds, Hopes This help Anyone
:PING_IP
set /p IP="Enter IP To Ping(0 Cancel): " || set "IP=0"
if %IP%==0 (
cls
goto IP_MENU
) else (
ping %IP%
pause
cls
goto IP_MENU
)

Related

lauterbach scripting: read peripheral

I am trying to check if a function is called every 2 miliseconds by way of a script. For this I need to read the value of a timer but I get the error 'memory access not allowed' when I try to read it(Data.Long(D:0xF00001010)). This is may code:
GLOBAL &calledFunction &result &difftime &start &end
&calledFunction = "func1"
Go
BREAK.SET &calledFunction /Program
WAIT !STATE.RUN() 5.0s
IF (STATE.RUN())
(
&result = "failed"
)
ELSE
(
&start = Data.Long(D:0xF00001010)
Go
WAIT !STATE.RUN() 5.0s
IF (STATE.RUN())
(
&result = "failed"
)
ELSE
(
&end = Data.Long(D:0xF00001010)
&difftime = &start - &end
IF (&difftime == 2ms)
(
&result = "passed"
)
ELSE
(
&result = "failed"
)
)
)
break.Delete
break
ENDDO
Is there any way I can access the timer's value or maybe another solution to check if the function is called periodically? I tried using the runtime functions but the accuracy is not so good.

What its wrong in this code on Opencart 3.0.3.3

Whats its wrong in this code?
// Begin LJK - option display names
if (strlen(trim($option['display'])) != 0){
$option['name'] = $option['display'];
}
// End LJK - option display names
I have This Error on cart! But module works fine
Notice: Undefined index: display in /home/opencart/public_html/storage/modification/catalog/controller/checkout/cart.php on line 101
you should check if this display key exist in this array or not ( $option['display'] ) before use trim and strlen methods
so you should change your code to be like this :-
if ( !empty($option['display']) && strlen(trim($option['display'] ) ) != 0 ) {
$option['name'] = $option['display'];
}

Screen scraper script won't write to ouptut file

I can't get the Perl script below to write to the file output.html.
I doesn't need to be a CGI script yet, but that is the ultimate intention.
Can anyone tell me why it isn't writing any text to output.html?
#!/usr/bin/perl
#-----------------------------------------------------------------------
# This script should work as a CGI script, if I get it correctly.
# Most CGI scripts for Perl begin with the same line and must be
# stored in your servers cgi-bin directory. (I think this is set by
# your web server.
#
# This scripts will scrape news sites for stories about topics input
# by the users.
#
# Lara Landis
# Sinister Porpoise Computing
# 1/4/2018
# Personal Perl Project
#-----------------------------------------------------------------------
#global_sites = ();
print( "Starting program.\n" );
if ( !( -e "sitedata.txt" ) ) {
enter_site_info( #global_sites );
}
if ( !( -e "scrpdata.txt" ) ) {
print( "scrpdata.txt does not exist. Creating file now.\n" );
print( "Enter the search words you wish to search for below. Press Ctrl-D to finish.\n" );
open( SCRAPEFILE, ">scrpdata.txt" );
while ( $line = <STDIN> ) {
chop( $line );
print SCRAPEFILE ( "$line\n" );
}
close( SCRAPEFILE );
}
print( "Finished getting site data..." );
scrape_sites( #global_sites );
#----------------------------------------------------------------------
# This routine gets information from the user after the file has been
# created. It also has some basic checking to make sure that the lines
# fed to it are legimate domains. This is not an exhaustive list of
# all domains in existence.
#----------------------------------------------------------------------
sub enter_site_info {
my ( #sisites ) = #_;
$x = 1;
open( DATAFILE, ">sitedata.txt" ) || die( "Could not open datafile.\n" );
print( "Enter websites below. Press Crtl-D to finish.\n" );
while ( $x <= #sisites ) {
$sisites[$x] = <STDIN>;
print( "$sisites[$x] added.\n" );
print DATAFILE ( "$sisites[$x]\n" );
$x++;
}
close( DATAFILE );
return #sisites;
}
#----------------------------------------------------------------------
# If the file exists, just get the information from it. Read info in
# from the sites. Remember to create a global array for the sites
# data.
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Get the text to find in the sites that are being scraped. This requires
# nested loops. It starts by going through the loops for the text to be
# scraped, and then it goes through each of the websites listend in the
# sitedata.txt file.
#-----------------------------------------------------------------------
sub scrape_sites {
my ( #ss_info ) = #_;
#gsi_info = ();
#toscrape = ();
$y = 1;
#---------------------------
# Working code to be altered
#---------------------------
print( "Getting site info..." );
$x = 1;
open( DATAFILE, "sitedata.txt" ) || die( "Can't open sitedata.txt.txt\n" );
while ( $gsi_info[$x] = <DATAFILE> ) {
chop( $gsi_info[$x] );
print( "$gsi_info[$x]\n" );
$x++;
}
close( DATAFILE );
open( SCRAPEFILE, "scrpdata.txt" ) || die( "Can't open scrpdata.txt\n" );
print( "Getting scrape data.\n" );
$y = 1;
while ( $toscrape[$y] = <SCRAPEFILE> ) {
chop( $toscrape[$y] );
$y++;
}
close( SCRAPEFILE );
print( "Now opening the output file.\n" );
$z = 1;
open( OUTPUT, ">output.html" );
print( "Now scraping sites.\n" );
while ( $z <= #gsi_info ) { #This loop contains SITES
system( "rm -f index.html.*" );
system( "wget $gsi_info[$z]" );
$z1 = 1;
print( "Searching site $gsi_info[$z] for $toscrape[$z1]\n" );
open( TEMPFILE, "$gsi_info[$z]" );
$comptext = <TEMPFILE>;
while ( $comptext =~ /$toscrape[z1]/ig ) { # This loop fetches data from the search terms
print( "Now scraping $gsi_info[$z] for $toscrape[$z1]\n" );
print OUTPUT ( "$toscrape[$z1]\n" );
$z1++;
}
close( TEMPFILE );
$z++;
}
close( OUTPUT );
return ( #gsi_info );
}
You're making assumptions about the current work directory that are often incorrect. You seem to assume the current work directory is the directory in which the script resides, but that's never guaranteed, and it's often / for CGI scripts.
"sitedata.txt"
should be
use FindBin qw( $RealBin );
"$RealBin/sitedata.txt"
There could also be a permission error. You should include the error cause ($!) in your error message when open fails so you know what is causing the problem!
While you're checking some, you're not checking all of your open or system calls. If they fail, the program will keep going without an error message telling you why.
You can add checks to all of these, but it's easy to forget. Instead, use autodie to do the checks for you.
You'll also want to use strict to ensure you haven't made any variable typos, and use warnings to warn you about small mistakes. See this answer for more.
Also #global_sites is empty so enter_site_info() isn't going to do anything. And scrape_sites() does nothing with its argument, #ss_info.
All of these things are helpful. Thank you. I found the problem. I was opening the wrong file. It was putting the error-checking in on the file that let me spot the error. It should have been
open (TEMPFILE, "index.html") || die ("Cannot open index.html\n");
I have taken as many of the suggestions as I remembered and included them in the code. I still need to implement the directory advice, but it should not be difficult.

having an issue with an if then statement using vbYesNo

I am trying to create a script that will ask the user if they want to set a network printer as their default. My problem is that no matter what they select (yes or no) it set it up as the default and it always echo's my the echo statement under else. Can someone tell me what I am doing wrong?
` ' Printers.vbs - Windows Logon Script.
printername = "DCPTTEAM462W"
server = "DCDEPLOY03"
Dim objectNetwork, printer
printer = "\\DCPRINT03\DCPTTEAM462W"
Msgbox printername & " will now install on your computer.",0, "Add printer" & printername
intRespnseY = Msgbox("Would you like " & printername & " to be set as your default printer", vbYesNo, "Set as Default")
If intResponseY = vbNo Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection printer
WScript.Echo "DCPTTEAM462W was added as a printer."
Else
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection printer
objNetwork.SetDefaultPrinter printer
WScript.Echo "DCPTTEAM462W has been set as your default printer."
End If
`
You have a typo:
intRespnseY = Msgbox(....
Should be
intResponseY = Msgbox(....
Use
Option Explicit
to avoid blunders like:
intRespnseY = Msgbox("...")
If intResponseY = vbNo Then
(mark the missing "o")

Batch file complicated if sequence returns errors.

I am trying to have users login and when they do it sets their power or rank. The ranks are Admin User and Guest. I need to do the code below for every command in the program. It returns ) was not expected at this time. Any idea why? For this command all the users should be able to access it but later I will need to set certain things for each group.
if %inputCommand%==/help (
if %power%==Admin (
goto helpInfo
) else (
if %power%==User (
goto helpInfo
) else (
if %power%==Guest (
) else (
goto powerReadFailed
)
)
)
) else (
goto readInputCommandTwo
)
Try this:
if "%inputCommand%"=="/help" (
if "%power%"=="Admin" (
goto helpInfo
) else (
if "%power%"=="User" (
goto helpInfo
) else (
if "%power%"=="Guest" (
rem
) else (
goto powerReadFailed
)
)
)
) else (
goto readInputCommandTwo
)
Why so complicated?
how about
for %%a in (admin user guest) do if /i "%power"=="%%a" (
for %%b in (help somethingelse whatever) do if /i "%inputcommand"=="%%b" (
goto %%a%%b
)
goto %%ainvalidcommand
)
:powerreadfailed
you can then set up labels
adminhelp userhelp guesthelp
adminsomethingelse usersomethingelse guetsomethingelse
...
It's perfectly legitimate to write
:adminhelp
:userhelp
echo admin and user get the same help
and adding a new user-class or command isn't hard...
( IF /i means make a case-insensitive comparison)