Batch - Pass variable parameters onto batch files that contain spaces - windows

When my program finds itself outdated, it runs the updater 'data1.bat'.
In this case, i found that cmd was completely ignoring the double quotes in the command
This is the line of code (with variables(Original)):
start "" "%dirofbatch%data1.bat" "%downloc%" "%dirofbatch%" "%lver%" "%lget%"
This is the line of code (with those variables expanded):
start "" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7\data1.bat" "\\SERVER\Users\Test User\Minecraft Hunger Games Client v4.8" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7" "4.7" "4.8"
Instead of working, it seems to see:
start "" C:\Users\Hello\Desktop\Minecraft User\Minecraft Hunger Games
I found that out when every-time it ran, it started minecraft on my desktop, tried to login with the user name "User\Minecraft", the password "Hunger" and then tried to login to the server "Games"...
Is it possible to pass parameters with spaces to another batch program without this happening?

It's a bug of START or better of cmd, if in the path of the command is a space and at least in one parameter it fails.
A workaround to add a CALL
start "" CALL "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7\data1.bat" "\\SERVER\Users\Test User\Minecraft Hunger Games Client v4.8" "C:\Users\Hello\Desktop\Minecraft Client\Versions\4.7" "4.7" "4.8"

Related

How to deal with shell commands that never stops

Here is the case;
There is this app called "termux" on android which allows me to use a terminal on android, and one of the addons are androids API's like sensors, tts engines, etc.
I wanted to make a script in ruby using this app, specifically this api, but there is a catch:
The script:
require('json')
JSON.parse(%x'termux-sensor -s "BMI160 Gyro" -n 1')
-s = Name or partially the name of the sensor
-n = Count of times the command will run
returns me:
{
"BMI160 Gyroscope" => {
"values" => [
-0.03...,
0.00...,
1.54...
]
}
}
I didn't copied and pasted the values, but that's not the point, the point is that this command takes almost a full second the load, but there is a way to "make it faster"
If I use the argument "-d" and not use "-n", I can specify the time in milliseconds to delay between data being sent in STDOUT, it also takes a full second to load, but when it loads, the delay works like charm
And since I didn't specify a 'n' number of times, it never stops, and there is the problem
How can I retrieve the data continuously in ruby??
I thought about using another thread so it won't stop my program, but how can I tell ruby to return the last X lines of the STDOUT from a command that hasn't and will not ever stop since "%x'command'" in ruby waits for a return?
If I understood you need to connect to stdout from a long running process.
see if this works for your scenario using IO.popen:
# by running this program
# and open another terminal
# and start writing some data into data.txt
# you will see it appearing in this program output
# $ date >> data.txt
io_obj = IO.popen('tail -f ./data.txt')
while !io_obj.eof?
puts io_obj.readline
end
I found out a built in module that saved me called PTY and the spawn#method plus thread management helped me to keep a variable updated with the command values each time the command outputted new bytes

Terraform GCP Instance Metadata Startup Script Issue

I've been working with Terraform, v0.15.4, for a few weeks now, and have gotten to grips with most of the lingo. I'm currently trying to create a cluster of RHEL 7 instances dynamically on GCP, and have, for the most part, got it to run okay.
I'm at the point of deploying an instance with certain metadata passed along to it for use in scripts built into the machine image for configuration thereafter. This metadata is typically just passed via an echo into a text file, which the scripts then pickup as required.
It's... very simple. Echo "STUFF" > file... Alas, I am hitting the same issue OVER AND OVER and it's driving me INSANE. I've Google'd around for ages, but all I can find is examples of the exact thing that I'm doing, the only difference is that theirs works, mine doesn't... So hopefully I can get some help here.
My 'makes it half-way' code is as follows:
resource "google_compute_instance" "GP_Master_Node" {
...
metadata_startup_script = <<-EOF
echo "hello
you" > /test.txt
echo "help
me" > /test2.txt
EOF
Now the instance with this does create successfully, although when I look onto the instance, I get one file called ' /test.txt? ' (or if I 'ls' the file, it shows as ' /test.txt^M ') and no second file.. I can run any command instead of echo, and whilst the first finishes, the second+ does not. Why?? What on earth is causing that??
The following code I found also, but it doesn't work for me at all, with the error, 'Blocks of type "metadata" are not expected here.'
resource "google_compute_instance" "GP_Master_Node" {
...
metadata {
startup-script = "echo test > /test.txt"
}
Okaaaaay! Simple answer for a, in hindsight, silly question (sort of). The file was somehow formmated in DOS, meaning the script required a line continuation character to run correctly (specifically \ at the end of each individual command). Code as follows:
resource "google_compute_instance" "GP_Master_Node" {
...
metadata_startup_script = <<-EOF
echo "hello
you" > /test.txt \
echo "help
me" > /test2.txt \
echo "example1" > /test3.txt \
echo "and so on..." > /final.txt
EOF
However, what also fixed my issue was just 'refreshing' the file (probably a word for this, I don't know). I created a brand new file using touch, 'more'd the original file contents to screen, and then copy pasted them into the new one. On save, it is no longer DOS, as expected, and then when I run terraform the code runs as expected without requiring the line continuation characters at the end of commands.
Thank you to commentors for the help :)

Error encountered when running batch file - was unexpected at this time

I have encountered an error when running a batch file. It goes like this, I run test-setup.cmd which calls another batch file test-env.cmd
test-setup.cmd calls by using this line:
call %SCRIPT_HOME%\test-env.cmd
where SCRIPT_HOME is set up as SCRIPT_HOME=%~dp0
test-env.cmd has this line:
if [%TEST_HOME%] == [] set TEST_HOME=D:\Program Files\Test\test-02.2.3.Final
After running the test-setup.cmd a message appears like this:
Files\Test\test-02.2.3.Final was unexpected at this time
Note that I have setup the TEST_HOME in the system environment variables.
Please help, thank you.
The syntax of your if command is incorrect. It would work if %TEST_HOME% didn't contain any spaces, but since it does you must use double quotes:
if "%TEST_HOME%" == "" set TEST_HOME=D:\Program Files\Test\test-02.2.3.Final
Mind you, since you're just testing to see whether the variable exists, it would be a lot more efficient to do that directly:
if not defined TEST_HOME set TEST_HOME=D:\Program Files\Test\test-02.2.3.Final

Properties in JMeter for GUI and CMD

I have a JMeter script, where I have some user defined Variables like FILE_SAVE_PATH. This script should be started on a command line with parameter -J. So in the GUI, I changed the value for the variable FILE_SAVE_PATH to ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}, because the test should save there a file, but only on my machine. On the machine, where the script will be started from command line, it should save the file into another path.
My problem is now this: When I test this JMeter script on my machine in the GUI, I get an output of this:
About to replace in property of type: class org.apache.jmeter.testelement.property.StringProperty: ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}
2017/04/04 17:09:38 DEBUG - jmeter.testelement.property.AbstractProperty: Not running version, return raw function string
2017/04/04 17:09:38 DEBUG - jmeter.engine.util.ValueReplacer: Replacement result: ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}
But I think, the last line should be something like this:
2017/04/04 17:09:38 DEBUG - jmeter.engine.util.ValueReplacer: Replacement result: "C:\svn\trunk\dir"
So, how to change the test to get the result I want?
Escape every backslash with another one - C:\\svn\\trunk\\dir, or use unix slash, JVM's gonna handle it right: C:/svn/trunk/dir
And remove the doublequotes, they're not needed.
P.S. I presumed you're not using that notation in the Beanshell/JSR223 context. If you do - stop there and use the legit way to access properties.

startup script in freebsd is not running

I have been trying to run a shell script at boot time of freebsd. I have read all simmilar questions in stackoverflow and tried. But nothing is worked. This is the sample code that i tried is dummy.
#!/bin/sh
. /etc/rc.subr
name="dummy"
start_cmd="${name}_start"
stop_cmd=":"
dummy_start()
{
echo "Nothing started."
}
load_rc_config $name
run_rc_command "$1"
Saved with name of dummy.
Permissions are -r-xr-xr-x.
in rc.conf file made dummy_enable="YES".
The problem is, when i rebooted my system to test, dummy file is not there. So script is not executing. what else need to do run my dummy script.
SRC:http://www.freebsd.org/doc/en/articles/rc-scripting/article.html#rc-flags
You need to add rcvar="dummy_enable" to your script. At least for FreeBSD 9.1.
Call your script with parameter rcvar to get the enabled status:
# /etc/rc.d/dummy rcvar
# dummy
#
dummy_enable="YES"
# (default: "")
And finally start it with parameter start - this won't start the service/script unless dummy_enable is set in /etc/rc.conf (or /etc/rc.conf.local, or /etc/defaults/rc.conf)
# /etc/rc.d/dummy start
Nothing started.
One possible explanation is that rcorder(8) says:
Within each file, a block containing a series of "REQUIRE", "PROVIDE",
"BEFORE" and "KEYWORD" lines must appear.
Though elsewhere I recall that if a file doesn't have "REQUIRE", "PROVIDE" or "BEFORE", then it will be arbitrarily placed in the dependency ordering. And, it could be that the arbitrary placement differs between the first run up to $early_late_divider and in the second run of those after $early_late_divider.
OTOH, is this a stock FreeBSD, or some variant? I recall reading that FreeNAS saves its configuration somewhere else and recreates its system files on every boot. And, quite possibly that /etc is actually on a ramdisk.
Also, /usr/local/etc/rc.d doesn't come into existence until the first port installing an rc file is installed.

Resources