You are missing the MIH / MIPv6 addition provided by ns-2.29-nist-mob-022707.tgz.This is for ns-2.29,but I usens-allinone-2.35.Is it the same procedure? Thanks!
This is my code link
https://drive.google.com/file/d/1Aan1OeAh5tIeDrt5MjgFTqvNSeahNWVy/view?usp=sharing
While running my tcl script for new protocol in NS2 it shows error as:
num_nodes is set 10
invalid command name "Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1"
while executing
"Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1 create _o216 "
invoked from within
"catch "$className create $o $args" msg"
invoked from within
"if [catch "$className create $o $args" msg] {
if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
delete $o
return ""
}
global errorInfo
error "class $..."
(procedure "new" line 3)
invoked from within
"new Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1"
invoked from within
"set handover [new Agent/MIHUser/IFMNGMT/MIPV6/Handover/Handover1]"
(file "bear2.tcl" line 177)
How can I modify it?
I am still confuse about eval and exac scenario as below;
1st scenario: exec ping "stackoverflow.com" -n 1
2nd scenario: eval exec [list ping //nologo "stackoverflow.com" -n 1]
3rd scenario: [list eval exec [list ping //nologo "stackoverflow.com" -n 1]]
The questions as below;
1. Difference tree above?
2. what is value number 1?
3. which one is good to use it?
Thanks in advance.
Starting with Tcl 8.5 (current is 8.6.8), the expansion
operator {*} (which breaks a list
into its component words) was added, and eval is rarely needed except
when evaluating scripts and script fragments.
With older versions of Tcl, eval is used instead of the expansion operator.
With the use of the expansion operator, #2 would become:
exec {*}[list ping /nologo "stackoverflow.com" -n 1]
There's nothing wrong with your #1, but there are a couple of common
patterns with the usage of exec where #2 is more useful.
a) Saving the command to be executed allows you to reuse it for a retry
or for debugging.
b) Commands can be built in a dynamic fashion.
foreach {host} [list stackoverflow.com stack_typo_exchange.com superuser.com] {
set cmd [list ping /nologo $host -n 1]
try {
exec {*}$cmd
} on error {err res} {
puts "ERROR: exec: $cmd"
puts " result: $res"
}
}
Older versions of Tcl would use the catch command:
if { [catch {eval exec $cmd}] } {
puts "ERROR: exec: $cmd"
}
Your #3 is (usually) not correct code. It is creating a list out of the return value from eval exec.
References: Tcl / argument expansion, try, catch, exec
I am running a program and want to see what its return code is (since it returns different codes based on different errors).
I know in Bash I can do this by running
echo $?
What do I do when using cmd.exe on Windows?
The "exit code" is stored in a shell variable named errorlevel.
The errorlevel is set at the end of a console application. Windows applications behave a little differently; see #gary's answer below.
Use the if command keyword errorlevel for comparison:
if errorlevel <n> (<statements>)
Which will execute statements when the errorlevel is greater than or equal to n. Execute if /? for details.
A shell variable named errorlevel contains the value as a string and can be dereferenced by wrapping with %'s.
Example script:
my_nifty_exe.exe
rem Give resolution instructions for known exit codes.
rem Ignore exit code 1.
rem Otherwise give a generic error message.
if %errorlevel%==7 (
echo "Replace magnetic tape."
) else if %errorlevel%==3 (
echo "Extinguish the printer."
) else if errorlevel 2 (
echo Unknown Error: %errorlevel% refer to Run Book documentation.
) else (
echo "Success!"
)
Warning: An environment variable named errorlevel, if it exists, will override the shell variable named errorlevel. if errorlevel tests are not affected.
Testing ErrorLevel works for console applications, but as hinted at by dmihailescu, this won't work if you're trying to run a windowed application (e.g. Win32-based) from a command prompt. A windowed application will run in the background, and control will return immediately to the command prompt (most likely with an ErrorLevel of zero to indicate that the process was created successfully). When a windowed application eventually exits, its exit status is lost.
Instead of using the console-based C++ launcher mentioned elsewhere, though, a simpler alternative is to start a windowed application using the command prompt's START /WAIT command. This will start the windowed application, wait for it to exit, and then return control to the command prompt with the exit status of the process set in ErrorLevel.
start /wait something.exe
echo %errorlevel%
Use the built-in ERRORLEVEL Variable:
echo %ERRORLEVEL%
But beware if an application has defined an environment variable named ERRORLEVEL!
If you want to match the error code exactly (eg equals 0), use this:
#echo off
my_nify_exe.exe
if %ERRORLEVEL% EQU 0 (
echo Success
) else (
echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%
)
Note that if errorlevel 0 matches errorlevel >= 0.
See if /?.
Or, if you don't handle success:
if %ERRORLEVEL% NEQ 0 (
echo Failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
It's worth noting that .BAT and .CMD files operate differently.
Reading https://ss64.com/nt/errorlevel.html it notes the following:
There is a key difference between the way .CMD and .BAT batch files set errorlevels:
An old .BAT batch script running the 'new' internal commands: APPEND, ASSOC, PATH, PROMPT, FTYPE and SET will only set ERRORLEVEL if an error occurs. So if you have two commands in the batch script and the first fails, the ERRORLEVEL will remain set even after the second command succeeds.
This can make debugging a problem BAT script more difficult, a CMD batch script is more consistent and will set ERRORLEVEL after every command that you run [source].
This was causing me no end of grief as I was executing successive commands, but the ERRORLEVEL would remain unchanged even in the event of a failure.
It might not work correctly when using a program that is not attached to the console, because that app might still be running while you think you have the exit code.
A solution to do it in C++ looks like below:
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "tchar.h"
#include "stdio.h"
#include "shellapi.h"
int _tmain( int argc, TCHAR *argv[] )
{
CString cmdline(GetCommandLineW());
cmdline.TrimLeft('\"');
CString self(argv[0]);
self.Trim('\"');
CString args = cmdline.Mid(self.GetLength()+1);
args.TrimLeft(_T("\" "));
printf("Arguments passed: '%ws'\n",args);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( argc < 2 )
{
printf("Usage: %s arg1,arg2....\n", argv[0]);
return -1;
}
CString strCmd(args);
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
(LPTSTR)(strCmd.GetString()), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d)\n", GetLastError() );
return GetLastError();
}
else
printf( "Waiting for \"%ws\" to exit.....\n", strCmd );
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
int result = -1;
if(!GetExitCodeProcess(pi.hProcess,(LPDWORD)&result))
{
printf("GetExitCodeProcess() failed (%d)\n", GetLastError() );
}
else
printf("The exit code for '%ws' is %d\n",(LPTSTR)(strCmd.GetString()), result );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return result;
}
At one point I needed to accurately push log events from Cygwin to the Windows Event log. I wanted the messages in WEVL to be custom, have the correct exit code, details, priorities, message, etc. So I created a little Bash script to take care of this. Here it is on GitHub, logit.sh.
Some excerpts:
usage: logit.sh [-h] [-p] [-i=n] [-s] <description>
example: logit.sh -p error -i 501 -s myscript.sh "failed to run the mount command"
Here is the temporary file contents part:
LGT_TEMP_FILE="$(mktemp --suffix .cmd)"
cat<<EOF>$LGT_TEMP_FILE
#echo off
set LGT_EXITCODE="$LGT_ID"
exit /b %LGT_ID%
EOF
unix2dos "$LGT_TEMP_FILE"
Here is a function to to create events in WEVL:
__create_event () {
local cmd="eventcreate /ID $LGT_ID /L Application /SO $LGT_SOURCE /T $LGT_PRIORITY /D "
if [[ "$1" == *';'* ]]; then
local IFS=';'
for i in "$1"; do
$cmd "$i" &>/dev/null
done
else
$cmd "$LGT_DESC" &>/dev/null
fi
}
Executing the batch script and calling on __create_event:
cmd /c "$(cygpath -wa "$LGT_TEMP_FILE")"
__create_event
I have following code of Powershell where i am trying to sort lastest backup file of mysql database and then try to import this file
I am using the Powershell script for this according to script till the last i get desired o/p and then i copy this o/p and execute in seprate
cmd window it execute smooth but in power shell when i try to do the same thing it fails with following error please help me
Error message
C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe --user=root --password=xxx testdest < "C:\mysqltemp\testsrc_2013-12-23_10-46-AM.sql"
cmd.exe : The system cannot find the file specified.
At C:\Users\IBM_ADMIN\AppData\Local\Temp\8a7b4576-97b2-42aa-a0eb-42bb934833a6.ps1:19 char:4
+ cmd <<<< /c " "$pathtomysqldump" --user=$param1 --password=$param2 $param3 < $param5 "
+ CategoryInfo : NotSpecified: (The system cann...file specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Script is as following
##Select latest file created by Export of mysql dumper
$a=(get-childitem C:\mysqltemp | sort LastWriteTime -Descending | Select-Object Name | select -first 1 -ExpandProperty Name)
$pathtomysqldump = "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe"
#Write-Host "Print variable A -------------"
#$a
$a=$a.Replace(" ", "")
#Write-Host "After Triming ---------------"
#$a
$param1="root"
$param2="xxx"
$param3="testdest"
#$param4="""'<'"""
$param5="""C:\mysqltemp\$a"""
#$p1="$param1 $param2 $param3 < $param5"
# Invoke backup Command. /c forces the system to wait to do the backup
Write-Host " "$pathtomysqldump" --user=$param1 --password=$param2 $param3 < $param5 "
cmd /c " "$pathtomysqldump" --user=$param1 --password=$param2 $param3 < $param5 "
Thanks and Appreciate your help and time for the same.
This is a common misunderstanding involving calling command lines in the Windows operating system, particularly from PowerShell.
I highly recommend using the Start-Process cmdlet to launch a process instead of calling cmd.exe. It's much easier to mentally parse out and understand the path to the executable, and all of the command line parameters separately. The problem with your current script is that you're trying to call an executable file with the following name: C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe --user=root --password=xxx testdest < "C:\mysqltemp\testsrc_2013-12-23_10-46-AM.sql", which has been wrapped in a call to cmd.exe. Obviously, that file does not exist, because you're including all of the parameters as part of the filesystem path.
There are too many layers going on here to make it simple to understand. Instead, use Start-Process similar to the following example:
# 1. Define path to mysql.exe
$MySQL = "C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe"
# 2. Define some parameters
$Param1 = 'value1';
$Param2 = 'value2';
$Param3 = 'value 3 with spaces';
# 3. Build the command line arguments
# NOTE: Since the value of $Param3 has spaces in it, we must
# surround the value with double quotes in the command line
$ArgumentList = '--user={0} --password={1} "{2}"' -f $Param1, $Param2, $Param3;
Write-Host -Object "Arguments are: $ArgumentList";
# 4. Call Start-Process
# NOTE: The -Wait parameter tells it to "wait"
# The -NoNewWindow parameter prevents a new window from popping up
# for the process.
Start-Process -FilePath $MySQL -ArgumentList $ArgumentList -Wait -NoNewWindow;
I want to know the parent processs id of the parent inside expect script how would i do it.
I used tried to use and got this error
[sesiv#itseelm-lx4151 ~]$ invalid command name "id"
while executing
"id process parent "
invoked from within
"set parent_process_id [ id process parent ]"
also tried to do
puts "parent is ---$env(PPID)**"
but it gave me this
[sesiv#itseelm-lx4151 ~]$ can't read "env(PPID)": no such variable
while executing
"puts "parent is ---$env(PPID)**""
The id command is part of the Tclx package, you need to include it:
package require Tclx
Update
Since your system does not have the Tclx package, and based on your prompt, I guess you are running a Unix-like operating system, I am going to offer a solution which employs the ps command. This solution will not work under Windows.
# Returns the parent PID for a process ID (PID)
# If the PID is invalid, return 0
proc getParentPid {{myPid ""}} {
if {$myPid == ""} { set myPid [pid] }
set ps_output [exec ps -o pid,ppid $myPid]
# To parse ps output, note that the output looks like this:
# PID PPID
# 4584 613
# index 0="PID", 1="PPID", 2=myPid, 3=parent pid
set checkPid [lindex $ps_output 2]
set parentPid [lindex $ps_output 3]
if {$checkPid == $myPid} {
return $parentPid
} else {
return 0
}
}
# Test it out
set myPid [pid]
set parentPid [getParentPid]
puts "My PID: $myPid"
puts "Parent PID: $parentPid"