Translating Linux command prompt to windows PowerShell prompt - linux

Quick background: I previously used a remote Linux server for a project. Here I was able to pull up the Linux command window in the directory where files from another program were located, and enter a command such as lspp c= example_file.cfile -nographics. LSPP in this case is short for LS PrePost - through this command I was able to call LSPP in the background and have it reference the given *.cfile which contains various commands to be executed, such as depositing a given *.csv file with results, its name, etc.
I recently managed to install LSPP for windows locally, and am now trying to essentially translate the functionality of the command I executed in Linux, to Windows. I should add that I have no experience with CMD or Windows PowerShell...
The first thing I tried was to use cd C:\.... to set the directory to where the *.cfile is located and then enter the same lspp c= example_file.cfile -nographics from Linux, however, the response was that "lspp" was either spelled wrong or could not be found.
Next I tried setting the directory to the LSPP program folder, and using start LS-PrePost-4.7-x64 to at least start the program, but this didn't work either.
I would really appreciate it if someone could point me in the right direction here - thank you!

Related

can someone help me get python to run my scripts in CMD in windows 10 without having to cd to exact path each time.?

I'm trying to get python to run my scripts via CMD line.
note: idr if the book said where (a specific place to store my files for) python to access them but scanning back over the beginning I didn't find any relation to it.
According to this book https://automatetheboringstuff.com/2e/appendixb/ I am supposed to be able to type python (script.py) in command line just like this and it should run the script:
Here's the error I am getting upon execution, compared to the example from the book below it to show that this is supposed to work.
CMD LINE OUTPUT :
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Armagon>python conway.py
python: can't open file 'conway.py': [Errno 2] No such file or directory
C:\Users\Armagon>
As you can see I get a python Error and researching this has given me nothing I found useful.
Here is the exact sample quoted from the book:
Microsoft Windows [Version 10.0.17134.648]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\Al>python hello.py
Hello, world!
C:\Users\Al>
First off, doing some research I have found a way to make it work, by cd(change directory) to the direct path of the folder containing the scripts C:\Users\Armagon\Desktop\mystuff. This helps to verify that the script I am trying to run is in fact located there and I've spelled it correctly.
But, according to everything I've followed up to this point I shouldn't have to do it this way.
The scripts are on my desktop all in the same folder called mystuff.
Following this link as well as a video Add a directory to Python sys.path so that it's included each time I use Python
I added the mystuff folder to PYTHONPATH in environment variables exactly as suggested. Here is a partial output of the sys.path (ran from IDLE) that shows mystuff filepath is added, so I'm pretty sure I did that part right.
['', 'C:\\Program Files\\Python38\\Lib\\idlelib', 'C:\\Users\\Armagon\\Desktop\\mystuff']
Maybe I've confused what is supposed to be happening here
I am operating under the assumption (based off what I've learned so far) that when CMD executes the line: python (script).py
It's supposed to run python.
Which in turn python is supposed to find my scripts on desktop (by the PYTHONPATH environment variable I created) and execute the script typed in CMD.
I've tried a lot of things in the process of getting just this far. I'd really appreciate if someone could point out what it is I'm overlooking to run python scripts from my desktop just like the book. I'm not very skilled at present and will gladly add any information as needed if I have excluded pertinent info I apologize in advance.
You should be able to do this as long as the script is in the module search path, for example, the PYTHONPATH environment variable. You should then be able to run the script like this:
python -m script
Well, the cd way is the way to go to run a python file via the command prompt. There is no other way I can think of.
Follow these steps or this link -> https://www.wikihow.com/Use-Windows-Command-Prompt-to-Run-a-Python-File to do it:
1)Open command prompt. type cmd or command prompt in search bar or run and press enter key.
2)In command prompt, given that the folder you are trying to access is in desktop, type-> cd desktop\myStuff.. Press enter.
3)Just write- python filename.py and enter.
4)It should run automatically.

Python 3 os.renames Access Denied only when used in a script

So I wrote a deployment script in python that essentially just moves a bunch of directories around. It may or may not be relevant that I'm working on Windows and the scripts manipulates files and directories in Windows network shares.
A requirement of this script is it moves the old binary directory to a backup location on the same Windows network share, and that's where I'm having the problem. I'm using os.renames for this task. The destination path is generated based on the timestamp of the executable in the bin directory.
exec_mtime = datetime.fromtimestamp(os.path.getmtime(server_exec_path))
new_dirname = os.path.basename(target_path) + '_' + exec_mtime.strftime('%Y-%m-%d_%H.%M.%S')
backup_target_dir = os.path.join(server_old_dir_path, new_dirname)
if not os.path.exists(backup_target_dir):
print("{0}: Backing up old software...".format(server))
os.renames(server_target_path, backup_target_dir)
else:
print("{0}: A backup already exists with the same version number. Skipping backup.".format(server))
As for my variables:
target_path == "//server/share/path/to/bin"
server_exec_path == os.path.join(target_path, 'Program.exe')
server_old_dir_path == "//server/share/path/to/bin_backup"
The os.renames command would resolve to something like this:
os.renames("//server/share/path/to/bin", "//server/share/path/to/bin_backup\\bin_2019-11-01_13.02.27")
So, my problem is that os.renames always throws PermissionError: [WinError 5] Access is Denied. I have double-checked the permissions on all of these directories and I have them. Here are some things I have tried so far:
Performing the same moves in the Windows file browser. -> It works.
Running the same os.renames command in the python3 shell with the same arguments the script would give it. -> It works, confusingly.
Putting the os.renames command in a loop to retry it 100 times if it fails (I read somewhere that it can help sometimes). -> It fails.
Running the script in an elevated PowerShell. -> It fails.
Hitting my laptop with a sledgehammer. -> Haven't tried yet.
Another thing I want to mention is the script used to work not even a few days ago. I did make some edits in the meantime, but they weren't related to this section of code.
I'm out of ideas on this one. So any help you can provide would be much appreciated.
As it turns out, the problem was a side-effect of the changes I made to my script. I use python to launch a psexec command against the same remote machine earlier in the script (to run taskkill locally so the software I'm updating can exit gracefully), and I used the -u flag, which changes the user with which the command runs on the remote machine. When I removed the -u flag os.renames started working again. So I'm guessing that somehow running psexec changed the user the python script uses when running os.renames.

Open python IDLE in specific Windows directory?

Issue: IDLE always starts using a specific windows directory: 'C:\Python36'. That is my installation directory. I do not want to keep my project files in that directory. I want files for a specific project in a separate project directory.
After hours of searching, I did not find an answer to my specific question. I did find a helpful clue in How to start IDLE (Python editor) without using the shortcut on Windows Vista?
The solution that meets my needs is to create a file: idlehere.py
import idlelib.pyshell
idlelib.pyshell.main()
I then place that file in my project directory and execute the file with
python idlehere.py
This starts IDLE in my project directory.
Even though this works for me, I am posting this question in case it helps others; or in case there is a better way to accomplish my objective.
UPDATE: From the comment and with further experience I have learned additional ways to start IDLE in a specific Windows directory.
For each case open a command prompt in the desired directory.
At the command prompt, enter python. That starts python in interactive mode.
To start idle enter: import idlelib.idle
At the command prompt, enter python -m idlelib
At the command prompt, enter python -m idlelib.idle

Node.Js windows command prompt change C:\ path to test directory instead

I'm trying to figure out if there is a way to change the Node.Js command prompt default path = C:\users...> (default when the prompt is launched) or C:\Windows\System (if launched with administrator privileges), to the location of the folder where i'm working.
Normally I have been doing C:\users..> cd C:\xampp\htdocs..... to navigate to the test folder and run test. Although once the command prompt is closed it reverts back to C:\users...>.
To achieve what I want I came across using Z:>C:\xampp\htdocs\projects.... but this returns access denied with or without administrator privileges. Even if I try C:>C:\xampp\htdocs\projects.... still get the Access Denied for some unknown reason. To be honest I don't know what Z:> or C:> will result.
Is it possible to change the default prompt path to the path of the directory I am working in so that every time command prompt is launched it goes to that directory? In this case C:\xampp\htdocs\projects.... instead of C:\users...>
This seems like a general windows CMD question. Simply change the start up directory for CMD. See this SO post.
Once you're in that directory, you should be able to run the node command as normal.
Look inside your default nodejs installation folder for a file called nodevars.bat. Here is my path:
C:\Program Files\nodejs\nodevars.bat
Open this and look towards the bottom--the line I needed was on the very bottom. Here is the line from the git master:
if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%"
I changed mine to
if "%CD%\"=="%~dp0" cd /d "C:\Users\David\Desktop\work\J\math"
And now I am happier.
I had the same question, today, 4/11/22, and DuckDuckGo provided this as the number one result for my query. Since the question appears to be unanswered, I will try for those who might show up later.

psexec error code -1073740771

I'm trying to open up a Unity3D game.exe that is on a remote computer through my main desktop. I had tried to do this through a batch file, but was advised to try PsExec in its place.
So far, I've brought the Psexec program into my game.exe folder. I run the command line required to open the program and the window opens up for a fraction of a second before closing down due to an error. The error code it gives is: -1073740771.
I tried googling what this error actually is but I can't find anything. Does anyone know what this error relates to?
The command line I type is as follows:
psexec \\OtherComputer -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
I even tried the above line with -d after the -i, quotes around the C:... but it all results in the same thing.
PSExec wont know about other game resources that live without side the EXE. It will simply copy game.exe to the remote machine and execute it.
Try deleting or renaming the resource folder and running it on your local machine - it should do the same thing as its doing on the remote machine.
You cant do what you want with psexec unless the entire application is self contained within one single .exe file.
You may be able to manually copy the resource folders if you have admin access to the other machines and administrative shares are enabled, then execute with psexec using the -w option:
Copy the files to \\OtherComputer\C$\MyGame
Run psexec \\OtherComputer -w C:\MyGame -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
Might work ;o)
Use the -h parameter to elevate the permissions.

Resources