Adding variables in .txt file with windows batch command - windows

Windows batch command in Jenkins. I really need key,value environment on jenkins because I don't want to share my important info's in Github. I have to get them on Jenkins
I tried this one for windows but it is not working.
#echo off
(echo token= sample && echo header = https://sample.com && echo baseURI = www.sample.com && echo browser = Chrome && echo environment =MobileWeb)>src/main/resources/Global.properties
And this for Mac, which is working
echo '
#Edit this section, if need be
token = sample......
header = https://sample
baseURI = \sample.com/
browser = Chrome
environment =MobileWeb
'>src/main/resources/Global.properties
Please help me for Windows.

Very simply:
#(
echo #Edit this section, if need be
echo token = sample
echo header = https://sample.com
echo baseURI = www.sample.com
echo browser = Chrome
echo environment = MobileWeb
) 1>"src\main\resources\Global.properties"

Related

Doxygen print bash file contents

I have a project with bash, python, and C files where I would like to simply print the contents of the bash file in the doxygen documentation.
I am using Doxygen 1.9.4 and my Doxyfile has the following modified settings:
JAVADOC_AUTOBRIEF = YES
PYTHON_DOCSTRING = NO
OPTIMIZE_OUTPUT_JAVA = YES
EXTENSION_MAPPING = sh=C
EXTRACT_ALL = YES
SORT_BRIEF_DOCS = YES
INPUT = .
FILTER_PATTERNS = *.sh="sh_filter"
FILE_PATTERNS += *.sh
The sh_filter file has the following contents
#!/bin/bash
echo "\verbatim"
echo "$(cat $1)"
echo "\endverbatim"
After running doxygen, there is nothing that appears in the file reference for the bash file that is within the working directory.
How can I get the file contents to be printed verbatim?
A bit long for a comment. The construction as requested is quite unusual as normally the purpose is to document routines / variables / classes / namespaces etc and support this with code. In this case the requirement is to just show the contents of the file.
The bests solution I found is to create the filter like:
#!/bin/bash
echo "/** \file"
echo "\details \verbinclude $1 */"
echo "$(cat $1)"
and have the following added to the doxygen settings file:
EXTENSION_MAPPING = sh=C
INPUT = .
FILTER_PATTERNS = *.sh="./sh_filter"
FILE_PATTERNS += *.sh
EXAMPLE_PATH = .
(where the different paths are depending on the local situation)

Writing multiline variable to file cmd

I am writing multiple lines in a variable to a file as part of my build step in groovy jenkins.
def output = GetProfiles()
String[] rev = output.toString().split("\n");
for(int i=0;i<rev.length;i++) {
String cred = rev[i]
bat "#echo off && echo $cred >> \"$tmpDir\\credentials\""
}
GetProfiles returns multiple lines of data and the above code works. However, it takes alot of time as it writes to the file line by line.
Is there a better approach to writing the entire set of lines in the variable to a file in one go? I tried encasing the echo command in () but that doesn't work.
bat "#echo off && (echo $output) > \"$tmpDir\\credentials\""
def output = GetProfiles().toString()
writeFile( file: "$tmpDir/credentials", text: output )

Why do special characters in a batch file print as a question mark?

So I was working on a batch file game a while ago, and for some reason it prints a question mark symbol instead of the smiley face symbol (which you get when you press Ctrl+A in a command prompt).
My Program ScreenShot
I have the same problem with these others symbols:
ctrl+a Smiley face
ctrl+b Dark smiley face
ctrl+d Diamond
ctrl+e Clover
ctrl+f Ace
ctrl+n Music symbol
crtl+o Some random circlish symbol
ctrl+p Left arrow
ctrl+q Right arrow
ctrl+r Up and Down arrows
ctrl+t Line wrap symbol
ctrl+u Double s
ctrl+v Thick underscore
ctrl+w Up and down arrow with a line at the bottom
ctrl+x Up arrow
ctrl+y Down arrow
Source from Instructables Article: How do you use special characters in cmd
I tried it with cmd ScreenShot
I am currently running Windows 10 Pro with the latest update. I have tried to find a solution to fix this problem but had no success. Any help would be appreciated.
The behavior of OEM Alt codes is misleading for codes 1-31 and 127. The system's OEM codepage is a superset of ASCII. However, this range of Alt codes doesn't input ASCII control characters, but rather the characters that old IBM PC systems would sometimes display and print for ASCII control characters. For example, Alt+1 enters "☺" (U+263A, white smiling face) instead of ASCII SOH (U+0001, start of heading). To compound this, the default behavior of WideCharToMultiByte when encoding such characters to the OEM codepage is to use the corresponding ASCII control character as the best-fit encoding. So a text editor may not warn you that what you see is not what you'll get.
The console doesn't display control characters as the old IBM PC graphics characters. It interprets some of them such as U+0009 (horizontal tab -- advance the cursor 8 spaces) and U+000D (carriage return -- advance the cursor to the beginning of the next line), but most of them are displayed as the current font's glyph for an unmapped character, such as a boxed question mark or an empty box. If you want to print "☺" to the console, then you should use the console's wide-character API, which works with Windows native Unicode (UTF-16LE) strings.
Fortunately CMD is a Unicode application, so there's no problem with printing "☺" to the console. The problem is what encoding to use for the batch script. The only general solution is to save the batch file as UTF-8 without a BOM (byte order mark). You'll need an IDE or text editor that can save UTF-8 without a BOM, such as Notepad++.
CMD decodes a batch script line by line using the legacy console codepage, which you can change to UTF-8 with the command chcp.com 65001. I advise against changing to UTF-8 permanently because, depending on the Windows version, the console has various bugs with codepage 65001. You can switch to UTF-8 temporarily to load non-ASCII strings as environment variables. Otherwise keep the rest of the batch file as strictly 7-bit ASCII to avoid localization problems.
Here's an example. There is probably a more generalized way to go about this than creating all of these local environment variables, but it's just to show that it works in principle.
graphics_ctl.bat
#echo off
REM ASCII Control-Character Graphics
REM File encoding: UTF-8 (no BOM)
REM Set the console to codepage 65001 (UTF-8).
for /f "tokens=2 delims=:" %%a in ('chcp.com') do set "CONSOLE_CODEPAGE=%%a"
set "CONSOLE_CODEPAGE=%CONSOLE_CODEPAGE: =%"
chcp.com 65001 >NUL
set "GCTL_WHITE_SMILING_FACE=☺"
set "GCTL_BLACK_SMILING_FACE=☻"
set "GCTL_BLACK_HEART_SUIT=♥"
set "GCTL_BLACK_DIAMOND_SUIT=♦"
set "GCTL_BLACK_CLUB_SUIT=♣"
set "GCTL_BLACK_SPADE_SUIT=♠"
set "GCTL_BULLET=•"
set "GCTL_INVERSE_BULLET=◘"
set "GCTL_WHITE_CIRCLE=○"
set "GCTL_INVERSE_WHITE_CIRCLE=◙"
set "GCTL_MALE_SIGN=♂"
set "GCTL_FEMALE_SIGN=♀"
set "GCTL_EIGHTH_NOTE=♪"
set "GCTL_BEAMED_EIGHTH_NOTES=♫"
set "GCTL_WHITE_SUN_WITH_RAYS=☼"
set "GCTL_BLACK_RIGHT_POINTER=►"
set "GCTL_BLACK_LEFT_POINTER=◄"
set "GCTL_UP_DOWN_ARROW=↕"
set "GCTL_DOUBLE_EXCLAMATION_MARK=‼"
set "GCTL_PILCROW_SIGN=¶"
set "GCTL_SECTION_SIGN=§"
set "GCTL_BLACK_RECTANGLE=▬"
set "GCTL_UP_DOWN_ARROW_WITH_BASE=↨"
set "GCTL_UP_ARROW=↑"
set "GCTL_DOWN_ARROW=↓"
set "GCTL_RIGHT_ARROW=→"
set "GCTL_LEFT_ARROW=←"
set "GCTL_RIGHT_ANGLE=∟"
set "GCTL_LEFT_RIGHT_ARROW=↔"
set "GCTL_BLACK_UP_TRIANGLE=▲"
set "GCTL_BLACK_DOWN_TRIANGLE=▼"
set "GCTL_HOUSE=⌂"
REM Restore the previous console codepage.
chcp.com %CONSOLE_CODEPAGE% >NUL
graphics_box.bat
#echo off
REM Box-Drawing Graphics
REM File encoding: UTF-8 (no BOM)
REM Set the console to codepage 65001 (UTF-8).
for /f "tokens=2 delims=:" %%a in ('chcp.com') do set "CONSOLE_CODEPAGE=%%a"
set "CONSOLE_CODEPAGE=%CONSOLE_CODEPAGE: =%"
chcp.com 65001 >NUL
set "GBOX_LIGHT_SHADE=░"
set "GBOX_MEDIUM_SHADE=▒"
set "GBOX_DARK_SHADE=▓"
set "GBOX_LIGHT_VERTICAL=│"
set "GBOX_LIGHT_VERTICAL_AND_LEFT=┤"
set "GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE=╡"
set "GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE=╢"
set "GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE=╖"
set "GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE=╕"
set "GBOX_DOUBLE_VERTICAL_AND_LEFT=╣"
set "GBOX_DOUBLE_VERTICAL=║"
set "GBOX_DOUBLE_DOWN_AND_LEFT=╗"
set "GBOX_DOUBLE_UP_AND_LEFT=╝"
set "GBOX_UP_DOUBLE_AND_LEFT_SINGLE=╜"
set "GBOX_UP_SINGLE_AND_LEFT_DOUBLE=╛"
set "GBOX_LIGHT_DOWN_AND_LEFT=┐"
set "GBOX_LIGHT_UP_AND_RIGHT=└"
set "GBOX_LIGHT_UP_AND_HORIZONTAL=┴"
set "GBOX_LIGHT_DOWN_AND_HORIZONTAL=┬"
set "GBOX_LIGHT_VERTICAL_AND_RIGHT=├"
set "GBOX_LIGHT_HORIZONTAL=─"
set "GBOX_LIGHT_VERTICAL_AND_HORIZONTAL=┼"
set "GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE=╞"
set "GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE=╟"
set "GBOX_DOUBLE_UP_AND_RIGHT=╚"
set "GBOX_DOUBLE_DOWN_AND_RIGHT=╔"
set "GBOX_DOUBLE_UP_AND_HORIZONTAL=╩"
set "GBOX_DOUBLE_DOWN_AND_HORIZONTAL=╦"
set "GBOX_DOUBLE_VERTICAL_AND_RIGHT=╠"
set "GBOX_DOUBLE_HORIZONTAL=═"
set "GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL=╬"
set "GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE=╧"
set "GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE=╨"
set "GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE=╤"
set "GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE=╥"
set "GBOX_UP_DOUBLE_AND_RIGHT_SINGLE=╙"
set "GBOX_UP_SINGLE_AND_RIGHT_DOUBLE=╘"
set "GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE=╒"
set "GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE=╓"
set "GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE=╫"
set "GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE=╪"
set "GBOX_LIGHT_UP_AND_LEFT=┘"
set "GBOX_LIGHT_DOWN_AND_RIGHT=┌"
set "GBOX_FULL_BLOCK=█"
set "GBOX_LOWER_HALF_BLOCK=▄"
set "GBOX_LEFT_HALF_BLOCK=▌"
set "GBOX_RIGHT_HALF_BLOCK=▐"
set "GBOX_UPPER_HALF_BLOCK=▀"
REM Restore the previous console codepage.
chcp.com %CONSOLE_CODEPAGE% >NUL
graphics_test.bat
#echo off
setlocal
set "scriptdir=%~dp0"
call "%scriptdir%\graphics_ctl.bat"
call "%scriptdir%\graphics_box.bat"
echo.
echo ASCII Control-Character Graphics
echo ----------------------------------------------
echo GCTL_WHITE_SMILING_FACE = %GCTL_WHITE_SMILING_FACE%
echo GCTL_BLACK_SMILING_FACE = %GCTL_BLACK_SMILING_FACE%
echo GCTL_BLACK_HEART_SUIT = %GCTL_BLACK_HEART_SUIT%
echo GCTL_BLACK_DIAMOND_SUIT = %GCTL_BLACK_DIAMOND_SUIT%
echo GCTL_BLACK_CLUB_SUIT = %GCTL_BLACK_CLUB_SUIT%
echo GCTL_BLACK_SPADE_SUIT = %GCTL_BLACK_SPADE_SUIT%
echo GCTL_BULLET = %GCTL_BULLET%
echo GCTL_INVERSE_BULLET = %GCTL_INVERSE_BULLET%
echo GCTL_WHITE_CIRCLE = %GCTL_WHITE_CIRCLE%
echo GCTL_INVERSE_WHITE_CIRCLE = %GCTL_INVERSE_WHITE_CIRCLE%
echo GCTL_MALE_SIGN = %GCTL_MALE_SIGN%
echo GCTL_FEMALE_SIGN = %GCTL_FEMALE_SIGN%
echo GCTL_EIGHTH_NOTE = %GCTL_EIGHTH_NOTE%
echo GCTL_BEAMED_EIGHTH_NOTES = %GCTL_BEAMED_EIGHTH_NOTES%
echo GCTL_WHITE_SUN_WITH_RAYS = %GCTL_WHITE_SUN_WITH_RAYS%
echo GCTL_BLACK_RIGHT_POINTER = %GCTL_BLACK_RIGHT_POINTER%
echo GCTL_BLACK_LEFT_POINTER = %GCTL_BLACK_LEFT_POINTER%
echo GCTL_UP_DOWN_ARROW = %GCTL_UP_DOWN_ARROW%
echo GCTL_DOUBLE_EXCLAMATION_MARK = %GCTL_DOUBLE_EXCLAMATION_MARK%
echo GCTL_PILCROW_SIGN = %GCTL_PILCROW_SIGN%
echo GCTL_SECTION_SIGN = %GCTL_SECTION_SIGN%
echo GCTL_BLACK_RECTANGLE = %GCTL_BLACK_RECTANGLE%
echo GCTL_UP_DOWN_ARROW_WITH_BASE = %GCTL_UP_DOWN_ARROW_WITH_BASE%
echo GCTL_UP_ARROW = %GCTL_UP_ARROW%
echo GCTL_DOWN_ARROW = %GCTL_DOWN_ARROW%
echo GCTL_RIGHT_ARROW = %GCTL_RIGHT_ARROW%
echo GCTL_LEFT_ARROW = %GCTL_LEFT_ARROW%
echo GCTL_RIGHT_ANGLE = %GCTL_RIGHT_ANGLE%
echo GCTL_LEFT_RIGHT_ARROW = %GCTL_LEFT_RIGHT_ARROW%
echo GCTL_BLACK_UP_TRIANGLE = %GCTL_BLACK_UP_TRIANGLE%
echo GCTL_BLACK_DOWN_TRIANGLE = %GCTL_BLACK_DOWN_TRIANGLE%
echo GCTL_HOUSE = %GCTL_HOUSE%
echo.
echo Box-Drawing Graphics
echo ----------------------------------------------
echo GBOX_LIGHT_SHADE = %GBOX_LIGHT_SHADE%
echo GBOX_MEDIUM_SHADE = %GBOX_MEDIUM_SHADE%
echo GBOX_DARK_SHADE = %GBOX_DARK_SHADE%
echo GBOX_LIGHT_VERTICAL = %GBOX_LIGHT_VERTICAL%
echo GBOX_LIGHT_VERTICAL_AND_LEFT = %GBOX_LIGHT_VERTICAL_AND_LEFT%
echo GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE = %GBOX_DOWN_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE = %GBOX_DOWN_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_DOUBLE_VERTICAL_AND_LEFT = %GBOX_DOUBLE_VERTICAL_AND_LEFT%
echo GBOX_DOUBLE_VERTICAL = %GBOX_DOUBLE_VERTICAL%
echo GBOX_DOUBLE_DOWN_AND_LEFT = %GBOX_DOUBLE_DOWN_AND_LEFT%
echo GBOX_DOUBLE_UP_AND_LEFT = %GBOX_DOUBLE_UP_AND_LEFT%
echo GBOX_UP_DOUBLE_AND_LEFT_SINGLE = %GBOX_UP_DOUBLE_AND_LEFT_SINGLE%
echo GBOX_UP_SINGLE_AND_LEFT_DOUBLE = %GBOX_UP_SINGLE_AND_LEFT_DOUBLE%
echo GBOX_LIGHT_DOWN_AND_LEFT = %GBOX_LIGHT_DOWN_AND_LEFT%
echo GBOX_LIGHT_UP_AND_RIGHT = %GBOX_LIGHT_UP_AND_RIGHT%
echo GBOX_LIGHT_UP_AND_HORIZONTAL = %GBOX_LIGHT_UP_AND_HORIZONTAL%
echo GBOX_LIGHT_DOWN_AND_HORIZONTAL = %GBOX_LIGHT_DOWN_AND_HORIZONTAL%
echo GBOX_LIGHT_VERTICAL_AND_RIGHT = %GBOX_LIGHT_VERTICAL_AND_RIGHT%
echo GBOX_LIGHT_HORIZONTAL = %GBOX_LIGHT_HORIZONTAL%
echo GBOX_LIGHT_VERTICAL_AND_HORIZONTAL = %GBOX_LIGHT_VERTICAL_AND_HORIZONTAL%
echo GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_DOUBLE_UP_AND_RIGHT = %GBOX_DOUBLE_UP_AND_RIGHT%
echo GBOX_DOUBLE_DOWN_AND_RIGHT = %GBOX_DOUBLE_DOWN_AND_RIGHT%
echo GBOX_DOUBLE_UP_AND_HORIZONTAL = %GBOX_DOUBLE_UP_AND_HORIZONTAL%
echo GBOX_DOUBLE_DOWN_AND_HORIZONTAL = %GBOX_DOUBLE_DOWN_AND_HORIZONTAL%
echo GBOX_DOUBLE_VERTICAL_AND_RIGHT = %GBOX_DOUBLE_VERTICAL_AND_RIGHT%
echo GBOX_DOUBLE_HORIZONTAL = %GBOX_DOUBLE_HORIZONTAL%
echo GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL = %GBOX_DOUBLE_VERTICAL_AND_HORIZONTAL%
echo GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_UP_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_UP_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_DOWN_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_DOWN_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_UP_DOUBLE_AND_RIGHT_SINGLE = %GBOX_UP_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_UP_SINGLE_AND_RIGHT_DOUBLE = %GBOX_UP_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE = %GBOX_DOWN_SINGLE_AND_RIGHT_DOUBLE%
echo GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE = %GBOX_DOWN_DOUBLE_AND_RIGHT_SINGLE%
echo GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE = %GBOX_VERTICAL_DOUBLE_AND_HORIZONTAL_SINGLE%
echo GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE = %GBOX_VERTICAL_SINGLE_AND_HORIZONTAL_DOUBLE%
echo GBOX_LIGHT_UP_AND_LEFT = %GBOX_LIGHT_UP_AND_LEFT%
echo GBOX_LIGHT_DOWN_AND_RIGHT = %GBOX_LIGHT_DOWN_AND_RIGHT%
echo GBOX_FULL_BLOCK = %GBOX_FULL_BLOCK%
echo GBOX_LOWER_HALF_BLOCK = %GBOX_LOWER_HALF_BLOCK%
echo GBOX_LEFT_HALF_BLOCK = %GBOX_LEFT_HALF_BLOCK%
echo GBOX_RIGHT_HALF_BLOCK = %GBOX_RIGHT_HALF_BLOCK%
echo GBOX_UPPER_HALF_BLOCK = %GBOX_UPPER_HALF_BLOCK%
Well, it depends on your code page. You can check it by going on command prompt and typing chcp, which well display your code page. Search it up and you'll find a list of characters you can write. Basically, it'll tell you which "special" characters you can type in that will be displayed. For example, mines is 850 (like a lot of others) and so can't display smiley faces. You can change your code page by:
Open Windows Control Panel
Select Region and Language
Click on the Administrative tab
Under Language for non-Unicode programs, click on Change System Locale
Choose the locale
Click OK
That's all, I think. Hope I helped!

Why Windows generate a lot of process for a compiled Perl script?

I've written this script (called SpeedTest.pl) to log internet speed due to resolve a problem with my ISP.
It work well, but just if I use a Perl interpreter (if I double-click on the script). I want to compile it to generate a stand-alone executable to run in a different PC without Perl installed.
Well, I've try with pp and Perl2Exe both, but when I launch the SpeedTest.exe i see a lot of process called "SpeedTest.exe" in task manager. If I don't block all these process, the PC OS will crash (a pop-up say: "the memory can't be written, blah blah blah).
Any ideas?
This is the script:
#!/usr/local/bin/perl
use strict;
use warnings;
use App::SpeedTest;
my($day, $month_temp, $year_temp)=(localtime)[3,4,5];
my $year = $year_temp+1900;
my $month = $month_temp+1;
my $date = "0"."$day"."-"."0"."$month"."-"."$year";
my $filename = "Speed Test - "."$date".".csv";
if (-e $filename) {
goto SPEEDTEST;
} else {
goto CREATEFILE;
}
CREATEFILE:
open(FILE, '>', $filename);
print FILE "Date".";"."Time".";"."Download [Mbit/s]".";"."Upload [Mbit/s]".";"."\n";
close FILE;
goto SPEEDTEST;
SPEEDTEST:
my $download = qx(speedtest -Q -C --no-upload);
my $upload = qx(speedtest -Q -C --no-download);
my #download_chars = split("", $download);
my #upload_chars = split("", $upload);
my $time = "$download_chars[12]"."$download_chars[13]"."$download_chars[14]"."$download_chars[15]"."$download_chars[16]";
my $download_speed = "$download_chars[49]"."$download_chars[50]"."$download_chars[51]"."$download_chars[52]"."$download_chars[53]";
my $upload_speed = "$upload_chars[49]"."$upload_chars[50]"."$upload_chars[51]"."$upload_chars[52]"."$upload_chars[53]";
my $output = "$date".";"."$time".";"."$download_speed".";"."$upload_speed".";";
open(FILE, '>>', $filename);
print FILE $output."\n";
close FILE;
sleep 300;
my($day_check, $month_temp_check, $year_temp_check)=(localtime)[3,4,5];
my $year_check = $year_temp_check+1900;
my $month_check = $month_temp_check+1;
my $date_check = "0"."$day_check"."-"."0"."$month_check"."-"."$year_check";
my $filename_check = "Speed Test - "."$date_check".".csv";
if ($filename = $filename_check) {
goto SPEEDTEST;
} else {
$filename = $filename_check;
goto CREATEFILE;
}
Well, Steffen really answered this by way of a Comment, but here it is as an Answer. Just compile your Perl into an EXE that does NOT have the same name as the one that the Perl script is calling, for example:
speedtest.pl compiled into myspeedtest.exe, which calls speedtest.exe

fopen with dynamic filename is not working

I need to make a web site on which people can upload data files that after some treatment will be plotted using the jpgraph. The file is analyzed with a bash script called analfile.sh. The bash script is like this:
#!/bin/bash
file=$1
fecha=`date +%s`
mv $1 $fecha.dat
echo $fecha.dat
So, it gives back another file which name is like: 1321290921.dat. That is the file that I need to plot.
This my current php code:
$target_path = "/home/myhome";
$target_path = $target_path . basename( $_FILES['rdata']['name']);
$target_file = basename( $_FILES['rdata']['name']);
if(move_uploaded_file($_FILES['rdata']['tmp_name'], $target_path)) {
echo "The file ". $target_file. " has been uploaded";
chdir('/home/myhome');
$filetoplot=shell_exec('./analfile.sh'.' '.$target_file);
} else{
echo "There was an error uploading the file, please <a href=\"index.html\">try again!
</a>";
}
//$filetoplot="1321290921.dat"
echo "<br>The file to be opened is ". $filetoplot. "<br>";
if ($file_handle = fopen("$filetoplot", 'r')) {
while ( $line_of_text = fgets($file_handle) ) {
$parts = explode('.', $line_of_text);
echo $line_of_text ;
print $parts[0] . $parts[1]. $parts[2]. "<br>";
}
fclose($file_handle);
}
I have permissions to read and write on the target directory. I find strange that if I uncomment the line $filetoplot="1321290921.dat" then the script works perfectly. I guess I am doing something stupid since this is my first code in php but after some hours googling I was not able to find a solution.
Any help will be appreciated.
First thing I'm seeing is that you don't append trailing slash (/) to your home path, so that the path would be like /home/myhomefoo rather than /home/myhome/foo.
You should also move $target_file earlier, and reuse that within $target_path. There's no reason to do the same thing twice.
If that doesn't help, we'll see what goes next.

Resources