I've been wondering if this is possible on jmeter wherein I copy the original image and rename it via random string and paste it in the same dir.
Yep, take a look at:
OS Process Sampler which allows execution of arbitrary external commands and programs
__RandomString() function which can generate a random string of the specified length from the specified characters
Example setup:
Related
I have a directory with a processing script and some .mp4 files, how do i choose a random one to display?
Break your problem down into smaller steps.
Can you write a program that simply lists all of the files in a directory? The File class might help, and the Java API is your best friend.
Can you write a program that takes that list of files and creates an array or ArrayList that contains all of them?
Can you write a program that takes an array or ArrayList and chooses a random element from it? Use hard-coded String values for testing.
When you get all of these individual steps working, you can combine them into a single program that chooses a random file from a directory. If you get stuck on a specific step, you can post a MCVE of just that step, and we'll go from there.
I use the PowerGUI editor to convert a ps1 file to an exe file. Reason is that I dont want people to see my source code. The script includes a own little GUI with a picture on it. My problem is that after converting the script to an exe file the picture will only be shown when it exists on a specific path. If I delete or move the picture from that path it wont be shown when starting the exe.
How can I include the picture to the exe? I want to have only one file in the end ...
One way you could do this is by converting your image into a Base 64 String, using the following:
[convert]::ToBase64String((get-content C:\YourPicture.jpg -encoding byte)) > C:\YourString.txt
With the string that is produced in the text file "C:\YourString.txt" you can copy and paste it into your code and load it into a picture object on the form like so:
$logo.Image = [System.Convert]::FromBase64String('
iVBORw0KGgoAAAANSUhEUgAAAfQAAACMCAYAAACK0FuSAAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAAXEQAAFxEByibzPwAAAAd0SU1FB98DFA8VLc5RQx4AANRpSURBVHhe7J0FmBTX0oZ7F1jc3d3d
nU+dOtXw4MGDZfft25fmyJEjPu+//76Xqzke8pCHPOQhD3lIQGxxcGSapvHdd9+FF3hHEdjGFHgn
....... Many more lines of string .......
OqelFQzDMAzD/CZoztADbUwhUm0JERoXCNfEQYhyPAQryiBIUQSBiiTwl1sb3skwDMMwzG+KWLVe
jTEBH6U7JvJ0CJQXoaGPQMWBm5W+Va27k14MwzDMfwCA/wfUstOLO+nBIAAAAABJRU5Jggg==')
Do this will mean that your image is stored within the code already and doesn't need to be loaded from somewhere.
Note: Make sure that the pictures size on disk is the smallest you can get it as producing the string can take sometime and could turn out thousands of lines long. So I would recommend that you only use a pic that is less that 75 Kilobytes in size. You could do it with larger one but this will take a long time to process.
I have a scenario where I have to upload a unique named text file.I have used counter in the thread level and using the reference name as file name.say If I want to upload the File_1.txt, I have used something like this file_${counter_refname}.This is working like a charm in single machine but, Now the problem is when I run in the distributed mode slave_1 is uploading the File_1.txt and Slave 2 machine is also uploading the same file File_1.txt. The Target server will not allow to upload file with same name. How to resolve this problem??
Use a CSVData Set that will contain file names.
Create 1 file per distributed node referenced by it and ensure all these files never contain the same file name.
To do it, first create 1 file with unique names then split it in as many files as you have nodes.
Another option is to just generate a unique file name if sequence number is not important by using __UUID function:
http://jmeter.apache.org/usermanual/functions.html#__UUID
There is a couple of functions which can help to identify slave machine and parametrize file name.
__machineName() - returns hostname of machine running JMeter instance
__machineIP() - the same for IP address
Also you can look into __Random() or __RandomString() functions to generate unique files with random names on the fly i.e. with Beanshell PreProcessor as follows:
import org.apache.commons.io.FileUtils;
String filename = "file_${__Random(10000,99999,)}.txt";
FileUtils.writeStringToFile(new File(filename), "a quick brown fox", "UTF-8");
vars.put("filename", filename);
Refer to generated file name as ${filename} where required.
Basically, I just wan't to know how can this be achieved.
For example, suppose that I have to exe files, app1.exe and app2.exe. Now, app2.exe does a specific job basing on some settings defined on it's variables. I wan't to know how can I code the app1.exe to generate app2.exe files while defining different settings (variables) for it, without using any config file, registry or similar.
I don't have a specific project with this problem, but I was just wondering how this can be done.
--Inspired by the famous Trojan Horse ProRat. It does the same thing, it generates server.exe file with predefined settings from its server creator (another exe file). Furthermore it can bound with other files such as images, audio, video etc.
After this period of time, I found a solution to this problem by using code injection on file.
Below is my solution on steps:
Since both exe files (app1.exe and app2.exe) are created by same person, you can create the app2.exe with some predefined variable values (like string setting1 = "${MYVAR}"), then compile and save the exe (app2.exe).
Include app2.exe as an embeded resource on app1.exe (the app2.exe generator), and get input (usually from user) that will be used to replace setting1 variables value of app2.exe
Read byte array of app2.exe on app1.exe (since it is embedded on it's resources) and convert it to HEX string
From the string (that is converted from byte array) find value of setting1 variable (by firstly converting it also in byte array then in HEX string), and then replace it with the input you got in step 2 (by also converting in byte array then in HEX string).
Convert the whole string (after replacing the values) back to byte array and save it as a file (app2.exe).
If someone want to see an example, I can put some code as proof of concept.
For example if the full file path of the exe is provided as C:\Projects\Executable\Serial Data Streaming Recorder.exe, I need to extract the name of the exe. That is Serial Data Streaming Recorder and I want to dynamically assign this value to a variable from the full file path of exe.
Manually done like in below example:
#define ExePath "C:\Projects\Executable\Serial Data Streaming Recorder.exe"
#define AppName "Serial Data Streaming Recorder"
I want to dynamically assign the value Serial Data Streaming Recorder to the variable AppName from the full file path of exe.
I'm using this name in many places in the inno script for many files, So i don't want to do it manually by assigning this value to a variable.
To do this at runtime in [Code] You can get the file name and extension using the ExtractFileName(). I think you can then remove the extension by passing blank to the ChangeFileExt() function but if not, you can find and remove it using standard string operations like Pos() and Delete().
If you need to do this at compile time, you need to use ISPP, most of the functions have the same name and signature so use ExtractFileName() to get the file name itself, RPos() to get the period and Delete() to remove it.
Hmm... I usually solve this simply by never using any absolute paths in my install scripts. You can also just define ExePath like this:
#define BasicName "Serial Data Streaming Recorder"
#define ExePath "C:\Projects\Executable\" + BasicName + ".exe"
and then use {#BasicName} whenever you need just the name.
There are also several preprocessor script functions (not pascalscript) that can do string manipulations to do more advanced stuff.