I have a program using Named Pipes to communicate with another process, but it fails in a user's computer when they're running Linux Proton emulating windows instead of native Windows. "Proton" is what Steam Deck devices uses to play Windows games. There is "Proton" and "Proton GE" and this fails in both cases.
import win32pipe, win32file
pipe = win32pipe.CreateNamedPipe(
r'\\.\pipe\\'+'my_pipe',
win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_WAIT,
1, 65536, 65536, 0, None)
win32file.SetFilePointer(pipe, 0, win32file.FILE_BEGIN)
No error in regular Windows.
Error in Linux "Proton" running Windows: pywintypes.error: (66, 'SetFilePointer', 'Bad device type.')
Any workaround for this? Or do I just have to abandon named pipes entirely when developing for users to use Proton? I was thinking about having it write to a file on disk instead of using named pipes and then polling that file, but that would be a last resort...
This is a bug in Linux Proton and doesn't look like it will be fixed any time soon.
The workaround was thus: Have the python program put the SetFilePointer in a try/except block. If it fails, fall back to a different protocol (an http protocol) and don't try to use named pipes.
Related
I amm writing a little python script that will grab information from VMs of Windows that I am running.
At the moment I can list the processes on a 32bit XP machine with the following method:
http://code.activestate.com/recipes/305279/
Is it possible to somehow detect the version of windows running and excute a different method for getting the processes on a 64bit machine, I am trying to get the processes from a 64Bit Vista and 64bit Windows 7.
Any ideas?
If you don't want to rely on any extra installed modules then you can parse the output of wmic, e.g.:
c:\> wmic process get description,executablepath
...
explorer.exe C:\Windows\explorer.exe
cmd.exe C:\Windows\SysWOW64\cmd.exe
conhost.exe C:\Windows\system32\conhost.exe
...
Reference: http://geekpedia.wordpress.com/2008/08/18/use-command-line-to-track-windows-processes/
There is another recipe on activestate that does a similar thing, but uses the Performance Data Helper library (PDH) instead.
I have tested this on my Windows 7 64bit machine and it works there - so presumably the same function will work on both 32bit and 64 bit windows.
You can find the recipe here: http://code.activestate.com/recipes/303339/
Another method is using WMI, there is an example here in Python using the wmi module:
http://timgolden.me.uk/python/wmi/cookbook.html
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
The cleanest way I found to solve this was to use the psutil library as recommended by Robert Lujo:
psutil.process_iter()
Note that it returns a generator object, issuing a process object at a time. For example if you need the list of process names, you can do something like:
[p.name() for p in psutil.process_iter()]
For similar purposes I have used psutil library. Some hints:
list processes with psutil.pids() (reference)
inspect process information with process = psutil.Process(pid) (reference)
do process.kill or process.terminate()
Installation on windows - pip will do installation from the source (which means compiling), so you probably want to download binary installation from https://pypi.python.org/pypi/psutil/#downloads.
You should be able to do this by exposing Windows Management Instrumentation within each VM. This tool gives you access to a bunch of system data, including processes, see http://technet.microsoft.com/en-us/library/cc757287%28WS.10%29.aspx
You should be able to popen one of the commands in the preceding link to get the info you're looking for.
I am trying to find a way to send a large amount of SIP INVITE from my linux OS to a remote application that accept SIP INVITE.
I found a way to send many SIP INVITE from the same source (i.e. ip.ethernetcard local linux os):
sipp -sn uac ip.remote.app -i ip.ethernetcard local linux os -m 10 -s "name.user"
This send 10 SIP INVITE. The problem is when I look at the log on the remote side (using tcpdump), I see that source is always the same (ip.ethernetcard local linux os). Is there a way to minimic different sources i.e. we are pretending that we have multiple clients talking to the remote app ?
Use some sip stress test tool such as SIPp to generate varied INVITE messages.
Injecting values from an external CSV during calls
You can use "-inf file_name" as a command line parameter to input values into the scenarios. The first line of the file should say whether the data is to be read in sequence (SEQUENTIAL), random order (RANDOM), or in a user based manner (USER). Each line corresponds to one call and has one or more ';' delimited data fields and they can be referred as [field0], [field1], ... in the xml scenario file. Example:
SEQUENTIAL
sipp1
sipp2
sipp3
...
Will be read in sequence (first call will use first line, second call second line). At any place where the keyword "[field0]" appears in the scenario file, it will be replaced by either "sipp1", "sipp2" or "sipp3" depending on the call.
As before, use
sipp -sn uac ip.remote.app -i ip.ethernetcard_local_linux_os -m 10 -s "name.user"
add -inf file_name and -sf uac.xml
In the xml file (standard example taken from sipp web page), replace
sip:sipp[local_ip]:[local_port]>;tag=[call_number]
sip:[field0]#[local_ip]:[local_port]>;tag=[call_number]
That is it.
In my project, we use the ACE ( Adaptive Communication Environment) middleware to write OS independent code that would run on both Windows and Linux.
The requirement is to the get the process id from process name.
Since ACE does not support this, we will have to use platform specific macros to separate the code for windows and linux.
For windows I would have to use either of - EnumProcesses or CreateToolhelp32Snapshot
How to do the same on linux using an API ?
Programming language is C++
if i understand your question correctly, you can do this from c++
char buf[512];
FILE *cmd_pipe = popen("pidof -s process_name", "r");
fgets(buf, 512, cmd_pipe);
pid_t pid = strtoul(buf, NULL, 10);
pclose( cmd_pipe );
here is an another example: Get process id by name in Linux using C++
Has anybody tried to connect to an abstract namespace path (which starts with a null character) on unix family addresses in nodejs?
The problem seems to be that node internally sets the encoding of the path to ascii and consequently converts '\0' to space character. I tried buffers but didn't change anything.
If you wanna know what "abstract namespace" in unix address family means see the paragraph titled "abstract:" in "Address format" section of this link: http://man7.org/linux/man-pages/man7/unix.7.html
It seems that special module should be used for:
https://www.npmjs.org/package/abstractsocket
Since 0.12 this is supported by the core net module.
For 0.10:
The the module proposed by socketpair uses child process api and an external utility socat (similar to netcat), and does not let you create servers, just client connections.
A better alternative is https://www.npmjs.com/package/abstract-socket - it is a binary module instead.
All standards compliant applications in Linux store a desktop schema in /usr/share/applications/. In my particular use case, I have a WnckWindow data structure and I can get a pid from that. Using this pid, I can extract the command line from the proc.
Unfortunately, it seems that the proc command line entry does not match the desktop schema launch parameters. For example, the 'thunderbird' application is launched via /usr/bin/thunderbird but this is just a shell script which activates the real executable: /usr/lib/thunderbird-8.0/thunderbird-bin.
The real executable cannot be launched directly as it is dependent on the library paths configured in the /usr/bin/thunderbird script. Does anyone have any advice on how to match process id numbers to the appropriate desktop schema without getting caught by the issue I've described?, Thanks.
Ok, well, it appears that there's no nice way of solving this using the pid, however, it is relatively easy to match the Wnck windows class to application desktop schemas. The Wnck windows class needs to be preprocessed a little first to ensure that the filter works but it's pretty trivial stuff. Once you've got a good set of target strings, eg 'Thunderbird' or 'Google' + 'Chrome', you can use the system application menu API to zero in on a likely candidate, for example, by using garcon on Xfce.