w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
sorting numbers into ascending order on a line
with open('input.txt') as f, open('output.txt', 'w') as out: for line in f: line = line.split() #splits the line on whitespaces and returns a list #sort the list based on the integer value of the item on the left side of the `:` line.sort(key = lambda x: int(x.split(':')[0])) out.write(" ".join(line) + ' ') output: 1076:1 1378:1 2561:1 2956:1 4118:1 1039:1 1662:1 894:1 1662:1 1797:1 1948:1

Categories : Python

Process a file after a file is finished being written Windows Command Line .bat
Getting the file size into a variable is simple - for %%F in (filePath) do set "size=%%~zF". But I believe I can give you a much better solution. Unlike Unix, most Windows processes get an exclusive lock on a file when they are writing to it. Assuming your conversion process continuously locks the output file during processing, then you can simply use the following to test if the file is locked (still being processed) or not locked (finished processing): ( (call ) >>outputFile.ext ) 2>nul && ( echo The file is unlocked and ready for transfer ) || ( echo The file is still being created ) The (call ) syntax is simply a very fast command that does nothing - effectively a null op. This command is guaranteed not to have any output, so when you append the results of the

Categories : Windows

How To Run A Python File From Windows Command Line
If you want to know How do I run a .py file from the Python interpreter? this will work import sys sys.path.append("C:\Users\Myname\Desktop\Python") import Python-Test But your question says from the command line, which has been answered in the comments.

Categories : Python

How to sort file names in ascending order?
you can use Collections.sort(fileList); to sort arraylist. Then use for(File file:fileList) System.out.println(file.getName()); Collections.sort()

Categories : Java

Writing and reading from a file and sort them in ascending order
You are missing to close the file after having written to it. Due to this the content most propably will be written when the application end, because to the then will be clsoed implicitly. Add fclose(f1) after the last fprintf() in createtestfile(). Secondly when reading from the file you should decide whether to use fgets() of fscanf() to read in the data. Or you can switch from reading from the file directly using fscanf() to do a sscanf() from the "string" you read using fgets(). To do so replace fscanf(fp, "%d", &value); with sscanf(buff, "%d", &value); Thirdly it makes no sense to try to write what you scanned in from buff back to buff, at least because you are overwriting buff in the next round of the read-loop. Also you pass buff to sort() which should

Categories : C

How to copy/cut a file (not the contents) to the clipboard in Windows on the command line?
You can try Swiss File Knife (SFK): sfk toclip Copy stdin to clipboard as plain text. type test.txt | sfk toclip Copies the content of ASCII file test.txt into the clipboard. sfk list | sfk toclip Copies a file listing of the current dir into the clipboard. sfk fromclip [-wait] [-clear] Dump plain text content from the clipboard to the terminal. -wait : block until plain text is available. -clear: empty the clipboard after reading it. Example: turn backslashes into forward slashes. Imagine you have the following text open within Notepad: foo/bar/systems/alpha1.cpp foo/bar/systems/alpha2.cpp foo/bar/systems/beta1.cpp And for some reason you need the first line in a format like this: fooarsystemsalpha1.cpp Then you may do it this way: Mark th

Categories : Windows

different order of command line options in a command affecting my output
getoptlong() is doing exactly what it is supposed to do. The format-string "d:g:hv" implies that the parameters d and g require a value. Anything specified following a command-line parameter is consider a value being passed to it. You should run your program as $program --download file --version Checkout this detailed example demonstrating the various aspects of using getoptlong(). How rm can handle the differing position of its cmd-line params? Apparently because rm's parameters (r, v etc.) do NOT accept any values as arguments. Thus directory does not get passed to any of them but rather is a separate cmd-line argument on its own. You can confirm this from the source-code of rm. To do something similar for your program, you will need to modify the optstring to "dghv" a

Categories : C

Why does quicksort take longer when sorted in descending order vs ascending order
If you want to count the number of iterations of the inner for loop, use long long. n*(n-1)/2 overflows an int for n = 100 000. If you want to count swaps, you should increment your counter whenever a swap is being done. Two easy optimizations to make to this are: pick the pivot randomly; make the partitioning function more efficient by using Hoare partitioning: http://cs.stackexchange.com/questions/11458/quicksort-partitioning-hoare-vs-lomuto There are others of course, but this should get you a decent algorithm.

Categories : C++

Remote command execution from command line in Windows XP
Maybe you could do that via Windows Scripting Host (WSH) which supported remote execution. See Setting up Remote WSH. The article contains a link to examples. (You may need to use the WshShell object to invoke taskkill from your remote script.)

Categories : Windows

How Can Be Used the Command Line of Developer Command Prompt in Vim on Windows?
You need to setup your PATH, INCLUDE and LIB environment variables. You could do that by running D:Program Files (x86)Microsoft Visual Studio 10.0VCvcvarsall.bat (or wherever it is located on your installation) in the same prompt you're running vim, or even manually setting these environment variables (here is a list of all values for VS2008 and Windows SDK: Using Visual Studio's 'cl' from a normal command line). However, you just can't run the bat file from vim directly, because it will open another Prompt, so the environment variables will be set only for that new prompt. The other option is just to create bat file which you can put it inside your PATH, for example cvim: call "D:Program Files (x86)Microsoft Visual Studio 10.0VCvcvarsall.bat" "C:Program Files (x86)Vimvim74g

Categories : C++

How to get command line output snippet if I know the line number in Windows?
Here's one way of doing it with a batch file, although it's not a very elegant solution. @echo off setlocal set currentservice="" set servicestate="" sc query state= all > services.txt for /f "delims=:; tokens=1,2" %%a in (services.txt) do call :findservice "%%a" "%%b" del services.txt echo %servicestate% endlocal goto :end :findservice if not %1 == "SERVICE_NAME" goto :findstate set currentservice=%2 goto :end :findstate if not %1 == " STATE " goto :end if not %currentservice% == " Telnet" goto :end set servicestate=%2 goto :end :end It first writes out the result of the sc query to a temporary file (services.txt). It then uses a for loop to process each line of that file. When it find a line starting with SERVICE_NAME, it saves the value of that name in t

Categories : Windows

Windows Dir command - order subdirectories by size
EDITED: to display largest to smallest folders See if this is what you need. d:files is the target tree here. @echo off for /f "delims=" %%a in (' dir "d:files" /ad /b /s ') do call :size "%%a" sort /r < "dirsize.tmp" del "dirsize.tmp" popd pause goto :eof :size for /f "tokens=3" %%b in ('dir "%~1" 2^>nul ^|find " File(s) "') do ( for /f "tokens=1-4 delims=," %%c in ("%%b") do ( set dirsize=%%c%%d%%e%%f ) ) set dirsize= %dirsize% set dirsize=%dirsize:~-20% >>"dirsize.tmp" echo %dirsize% "%~1" This is a sample of what I get from it: 27982878 "d:images+ Funny and Odd pictures" 22595308 "d:images+ Mostly Cats20120917" 16723196 "d:images+ Mostly Cats20130215" 10212204 "d:images+ Mostly Cats20121104" 9177080 "d:image

Categories : Windows

Passing each line of a file as command line argument to a binary file
Something this simple would normally be best handled by a "scripting" language, but it's pretty straight foreward in C++ as well. If you're reading your file from standard in: std::string args; while ( std::getline( std::cin, args ) ) { system( ("temp " + args).c_str() ); } should be all you need. (But you don't say what you want to do if temp fails.)

Categories : C++

Command works in command line but gives 'no such file or directory' in bash script
Remove the quotes around line 8. Like this: ./optAlg.exe "$inputFile" 500 2>&1 > "output/$outputFile" By placing quotes around the whole line you tell bash to execute a command which is called exactly ./optAlg.exe $inputFile 500 2>&1 > output/$outputFile and of course there is no such command. In reality you want to run ./optAlg.exe with parameters. Do not forget to place quotes around the variables because otherwise filenames that have whitespace characters are going to be passed as several arguments. Please read about arguments. And you can read about common pitfalls as well.

Categories : Bash

BufferedImage bytes have a different byte order, when running from Eclipse and the command line
Before answering my own question I would like to really, really, REALLY thank @Joni and @haraldK that pointed me to the right direction. My knowledge for the internals of the BufferedImage, ColorModel, SampleModel and the like is not so great so they have helped me out. So here is what happened: First of all the different behaviour was caused by different JREs. A log statement for printing the java version revealed that Eclipse prints 1.6.0_16-b01 while the command line prints 1.6.0_31-b05. Apparently the implementation of the image loading (this would be the PNGImageReader class) has changed between versions and I suspect that it did during this change. Still though both versions use the same ColorModel and SampleModel so I couldn't understand this change (it seemed a real code-breake

Categories : Java

Batch file/command to start a program through command line
I'll edit this if you respond to my comment but if you want to simply execute this command via a batch file (and you know nothing about batch files): Open a text editor (e.g.Notepad) Type in your command (e.g. c: andaotherfoldermyprogram.exe 10 20) Save the file as mybatchfile.cmd Double click the file (in Windows Explorer etc.)

Categories : Windows

How is interacting with a prompt of a third party command line program different from a Windows Command prompt?
Most likely the program starts its own shell and does no longer interact with the original one. (You would notice this if the program opens a new window) Or the program needs some specific library to be present to be able to interact with a shell (readline seems to be the case here) and that is not present in your Java Environment. As a quick hack you might try to start bash (or cmd) that then starts the tool. bash and cmd have readline library. I don't have a windows ready here but as a guess just try to call your program like cmd urjtag.exe instead of just urjtag.exe that way you start a cmd process (with that you can interact) and that cmd starts the urjtag.exe where you already know that it can interact with. Either way the problem lies in the way the program you want to call intera

Categories : Java

Ascending order after particular index
Create two arrays. The first with the items you want at the top and the rest in second. Use an NSSortDescriptor to sort the second array. NSSortDescriptor *ageDescriptor = [[NSSortDescriptor alloc] initWithKey:@"age" ascending:YES]; NSArray *sortDescriptors = @[ageDescriptor]; NSArray *sortedArray = [employeesArray sortedArrayUsingDescriptors:sortDescriptors];

Categories : Iphone

Python, Command Line, Windows
After modifying your path, did you start up a new instance of the command prompt (this has caused me much grief in the past)? To check if your path change was successful: echo %PATH% and check to see if C:Python2.7.5 was appended to it. If not then run: set PATH=%PATH%;C:Python2.7.5 To call a python script with a command line argument (assuming that your script is in the current working directory): python letter_counts.py "Your Text Goes Here" OR if you just want to be overly verbose (or your PATH still isn't right): C:Python2.7.5python.exe .letter_counts.py "Your text still goes here" EDIT: Make sure you are doing this from the command prompt and not the python interpreter. To access the command prompt you can hit: 1. Windows Key + R 2. type "cmd" (without quotes) and hit

Categories : Python

How to unsign an APK via command line in Windows
You can download zip for windows from this site: www.info-zip.org Direct link to Zip 3.0 for Windows just make sure to put it in a folder which is in the PATH variable

Categories : Android

Windows Command line get date
You can do this (date operations) very easily with some other language. Here are examples in Perl, Python, and Powershell. @ECHO OFF SETLOCAL SET PERL_CMD=perl -MPOSIX -e "print(POSIX::strftime(q(%%d-%%m-%%Y),localtime(time()-6*86400)));" FOR /F %%d IN ('%PERL_CMD%') DO SET PREV_DATE=%%d ECHO %PREV_DATE% SET PYTHON_CMD=py -3 -c "from datetime import *; print((datetime.now()+timedelta(days=-6)).strftime('%%d-%%m-%%Y'));" FOR /F %%d IN ('%PYTHON_CMD%') DO SET PREV_DATE=%%d ECHO %PREV_DATE% SET POWERSHELL_CMD=powershell -NoProfile -Command "Get-Date ((Get-Date).AddDays(-6)) -format dd.MM.yyyy" FOR /F %%d IN ('%POWERSHELL_CMD%') DO SET PREV_DATE=%%d ECHO %PREV_DATE% If you absolutely must do it in batch/CMD, then it could be (mostly) accomplished by parsing a date string and doing the m

Categories : Batch File

How to number input in ascending order?
You need to compare std::set<int>::iterator against the end() iterator of your set, rather than dereferencing the iterator and comparing its value against something! Actually, derferencing the end() iterator is undefined behavior: if ((*(sit = alreadyCounted.find(str1)).compare(str1) != 0) // WRONG: don't do that! should really be if (alreadyCounted.find(str1) != alreadyCounted.end()) ... and likewise for the other string. Personally, I would use a different technique, though: when insert()ing into a std::set<T>, you get back a pair of an iterator and an indicator whether the object was inserted. The latter together with the current set's size give the next value, e.g.: bool result = alreadyCounted.insert(str1).second; strNum1 = result? alreadyCounted.size() - 1: si->

Categories : C++

Rearrange LIST (Ascending Order)
sorting structure arguments it's a bit out of Prolog 'mainstream' coding. That's because arguments are really placeholders (exactly like columns in a RDB). You can do by means of univ (=..)/2 and msort/2 ?- Unsorted = dog(chiwawa,lucky,bull), Unsorted =.. [Functor|UnsortedArgs], msort(UnsortedArgs, Args), Sorted =.. [Functor|Args]. yields Unsorted = dog(chiwawa, lucky, bull), Functor = dog, UnsortedArgs = [chiwawa, lucky, bull], Args = [bull, chiwawa, lucky], Sorted = dog(bull, chiwawa, lucky). Of course, you probably should switch representation to lists, or will have an hard time with the remaining of your program. If you are trying to represent some kind of elementary classification, you could use library(pairs), and go with a list of Key-Elements. Something like dog-[bull, chiwa

Categories : Prolog

i want to arrange numbers in ascending order
You could store the values in an Array, or other Collection, and use Array.Sort. If you store them in separate variables then you would need to write the code that sorts them.

Categories : Dotnet

Sort NSDictionary in ascending order
Get the Array of the Values, sort that array and then get the key corresponding to the value. You can get the values with: NSArray* values = [myDict allValues]; NSArray* sortedValues = [values sortedArrayUsingSelector:@selector(comparator)]; But, if the collection is as you show in your example, (I mean, you can infer the value from the key), you can always sort the keys instead messing with the values. Using: NSArray* sortedKeys = [myDict keysSortedByValueUsingSelector:@selector(comparator)]; The comparator is a message selector which is sent to the object you want to order. If you want to order strings, then you should use a NSString comparator. The NSString comparators are i.e.: caseInsensitiveCompare or localizedCaseInsensitiveCompare:. If none of these are valid for you, you

Categories : Iphone

SQL - Order by ascending date difference from NOW()
SELECT advertise_id, qr_startdate, qr_enddate, DATEDIFF(NOW(), t1.qr_enddate) AS d FROM `adv_qr` t1 INNER JOIN advertise_table t2 ON t1.advertise_id = t2.lid ORDER BY d ASC

Categories : Mysql

Sort 2D array in ascending order
You are comparing elements that are not in the same row or column. Each sub-array should be sorted individually. You might want to reconsider this line if (B[ox][oy] < B[ix][iy]).

Categories : Java

Arrange List<> in ascending order
You can use LINQ OrderBy method (it will generate new List<string> with items sorted): var ordered = listCustomField.OrderBy(x => x).ToList(); or List<T>.Sort method (it will sort the list in place): listCustomField.Sort();

Categories : C#

Classpath format for Windows command line
java -classpath .;myjar.jar;lib/referenced-class.jar my.package.MainClass There is no need for <> brackets. For your application: java -classpath .;myjar.jar;lib/referenced-class.jar peersim.Simulator example1.txt If your application uses classes from myjar and others

Categories : Java

OS X command line java windows appearing
Well who knows what happened to Java but this answer provides the solution: How to set java system properties globally on OS X? i.e. ~/.profile export _JAVA_OPTIONS=-Djava.awt.headless=true

Categories : Java

output to command line from windows gui program
Most applications that need to accomplish this will create a *.com version of their app (which will sit alongside the .exe). All shortcuts will point to the .exe, but if the user happens to type the name on a command line, then the .com version will end up executing (as CMD will search for .com files before .exe files) The .com version is often a thin wrapper which will invoke the .exe and wait for it to finish or utilize shared .dll files, but it exists purely so that output can be funneled to the proper console window and won't "release" it until the application finishes. As an example, Microsoft's Visual Studio uses this approach: C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDE>dir devenv.* Volume in drive C has no label. Volume Serial Number is A482-59BA Directory

Categories : C

Add “python2” path to command line on Windows 7
This answer copied from my own answer, and customized to this question. Try following command. set path=%path%;c:python27 PATH is set only for the cmd.exe in which you run the above command. To permanently set PATH: Right click My computer in the desktop. Click Advanced System Settings on the left. Click Environmental Variable. Add or Update PATH variable: If it does not exist, create one, and set value as C:python27 If it exist, append ;C:Python27 to existing value. Restart cmd.exe. (PATH will not change for already launched cmd.exe)

Categories : Python

How to get command line of windows "open with .." function?
There is the SHOpenWithDialog function. Link to SHOpenWithDialog on MSDN However, you can't use this to retrieve the selected program. You can only use it to invoke the "Open With" behaviour and eventually open the file (if OAIF_EXEC is set). If that's all you're interested in, then try it out: #include <windows.h> #include <Shlobj.h> #pragma comment(lib, "Shell32.lib") int main() { OPENASINFO info = { 0 }; info.pcszFile = L"C:\Temp\SomeFile.png"; info.pcszClass = NULL; info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC; SHOpenWithDialog(NULL, &info); return 0; }

Categories : C++

Query an NTP Server using C# and windows command line
1) The most likely reason your program is stopping is because of no network response this can be caused by the network blocking for Udp, port 123 etc. 2) You can use the ntpq program to query from command line (NTP)

Categories : C#

Can't gzip my mysqldump on the command line windows
That is telling you that gzip is nowhere your system can find. You can blame however you installed gzip. Check the value of your $PATH environment (or system) variable. Then install a copy of gzip in one of those directories.

Categories : Mysql

Making a GUI operate from the Windows command line
To answer your first question, I recommend creating two different apps, one for command line and one for GUI. The only difference between the two is that one is built with code that handles command line input and the other would have code to use a GUI interface. The two would have in common the rest of the code that is interface agnostic, meaning it will work regardless of the interface. For the second question, there's plenty of tutorials out there for command line parsing, like this one I spent ten seconds to find.

Categories : C++

How can I know if a table is already arranged in ascending order in MySQL?
Data in a table is not arranged in any order. You have to explicitly specify an order when selecting the data. If you do not specify an order when selecting the data then the returned order is neither predictable nor reliable.

Categories : Mysql

Sorting double arrays into ascending order
That´s almost bubblesort you got there. try this : public static void sort(int[] x) { boolean sorted=true; int temp; while (sorted){ sorted = false; for (int i=0; i < x.length-1; i++) if (x[i] > x[i+1]) { temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; sorted = true; } } } But Collin is right. You are better off with Arrays.sort.

Categories : Java

HashSet giving the output in ascending order
HashSet makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time from HashSet JavaDoc.

Categories : Java

Sorting array values in ascending order
Use this: It assumes every array has only one element as per your example array. If it has many, modify it accordingly. function cmp( $a, $b ) { $key1 = array_keys( $a ); // all array keys in first array $key2 = array_keys( $b ); // all array keys in second array if ( $a[ $key1[ 0 ] ] == $b[ $key2[ 0 ] ] ) { return 0; } return ( $a[ $key1[ 0 ] ] < $b[ $key2 [ 0 ] ] ) ? -1 : 1; } uasort($weight, 'cmp'); Hope this helps.

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.